From patchwork Thu Feb 29 06:36:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoyao Li X-Patchwork-Id: 13576524 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 BCC694F1FE for ; Thu, 29 Feb 2024 06:38:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709188722; cv=none; b=sqPn+QpTmplz16ZtHPQv1BJE6NFJp8sklHh20JByNJGe3DUsXDejmp1jTM6dXCTHRRNdzRTmXsgJGY2M0e4KfwIYQjAs7VU58f1l4ZLdqGyy2l51IwOHwf7WveA9ZXwV/jCPKoX67kBky+KfLKvOZIssYofPCKG954LZWcvt01M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709188722; c=relaxed/simple; bh=R6P1mkE+VzbCklXI+XUrVzqW75xnxMrG1Ytrh3IX+7U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mvHnpFcbcpSKqFCRdpAH/9FOm/YLSYJg6I8nEVd2to85m4dASbZCLfWNGTwRpwu68qRuNf056KmSdiUliVnFny4fZH03az3clqe7VOmZHgC7b4lZTMJGn5nEQDDe0j397K6RGjJAhSpoi5t2tSB0GEc+GIG1btfUz6Uriy8GqRM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=YVngwO36; arc=none smtp.client-ip=192.198.163.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YVngwO36" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709188720; x=1740724720; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R6P1mkE+VzbCklXI+XUrVzqW75xnxMrG1Ytrh3IX+7U=; b=YVngwO36YsNljVdECMShQDPp/CEcdLAzoJa/ytMBTN/Cdou5Zjvc0/TV gA96lHTIfkbG1bqx18dVjGazUho+Q8XkoP2KPpOcRTMxmfz+tgfpbvf0E qTr9XQzOyeDYBZmGdJi06uDRFrVVmX2sSIynhcZt3NxDu/5wDDDMAKBcf 6Ci0iK4zlcBhZQaccnCIEKE88fcJMjqf0+y58clz8AQchkCH7lwpq25OP YwsG5cnjXdt7VhE0BJsVeFM1BAuMlkfSZJwDyoFhMWk2Y41ZQP86mpVfo fF6UxAqJ/jPxcVHrR8Lrr6fKEO3LwbyrDNg4gCvjnEGUzxc2q0VYxfpQJ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="3802555" X-IronPort-AV: E=Sophos;i="6.06,192,1705392000"; d="scan'208";a="3802555" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 22:38:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,192,1705392000"; d="scan'208";a="8075011" Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by orviesa007.jf.intel.com with ESMTP; 28 Feb 2024 22:38:34 -0800 From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , "Michael S. Tsirkin" , Richard Henderson , Ani Sinha , Peter Xu , Cornelia Huck , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: kvm@vger.kernel.org, qemu-devel@nongnu.org, Michael Roth , Claudio Fontana , Gerd Hoffmann , Isaku Yamahata , Chenyi Qiang , xiaoyao.li@intel.com Subject: [PATCH v5 10/65] kvm/memory: Make memory type private by default if it has guest memfd backend Date: Thu, 29 Feb 2024 01:36:31 -0500 Message-Id: <20240229063726.610065-11-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240229063726.610065-1-xiaoyao.li@intel.com> References: <20240229063726.610065-1-xiaoyao.li@intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 KVM side leaves the memory to shared by default, while may incur the overhead of paging conversion on the first visit of each page. Because the expectation is that page is likely to private for the VMs that require private memory (has guest memfd). Explicitly set the memory to private when memory region has valid guest memfd backend. Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index fe2eb3f06902..0c0719a0303c 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1451,6 +1451,16 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, strerror(-err)); abort(); } + + if (memory_region_has_guest_memfd(mr)) { + err = kvm_set_memory_attributes_private(start_addr, slot_size); + if (err) { + error_report("%s: failed to set memory attribute private: %s\n", + __func__, strerror(-err)); + exit(1); + } + } + start_addr += slot_size; ram_start_offset += slot_size; ram += slot_size;