From nobody Thu Nov 20 14:05:11 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1763573465; cv=none; d=zohomail.com; s=zohoarc; b=MFuhFM4yPLmAGQI6EJ8ADUkxgNEx6/I3RKU78fswJJ5tYnUjG93lt7euC6+36CL+oCbe6UvVKRNr3tisEKztZSqALD8F1yr4ii9ymdUwb2CyLZRZ45grIEh43GZXOsOr75ZljUE/TG+Svegt5QlKXF96Ho0YFi5DY+dUaKS/IeE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763573465; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=z/qhRlrhL2hHAQxy9Ba9VBELeFSbko3iP9NyeeHVbJY=; b=VEnqzIDxPJXFjuynog30RHBH98pBX/xHCj7wEg1fuZAYQUBMXKYvURJgUO6ws00fjgZR1B1vyB32yGWuwYSuaFOt03a8yNVKYubQXHnx1WETvkmCdZVCHpDhzvwus9CeX6ZqX2mxNKchAyaxWbHNjmFIJ/cqITr2Z3nocjxWhQk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1763573465950672.9131121747024; Wed, 19 Nov 2025 09:31:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLm03-00039q-3X; Wed, 19 Nov 2025 12:29:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLlzi-000314-NR for qemu-devel@nongnu.org; Wed, 19 Nov 2025 12:29:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLlzg-0004Nn-7K for qemu-devel@nongnu.org; Wed, 19 Nov 2025 12:29:26 -0500 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-326-7kpSR_5VO6qrTFbNrR6weg-1; Wed, 19 Nov 2025 12:29:20 -0500 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8b26bc4984bso1317388085a.1 for ; Wed, 19 Nov 2025 09:29:20 -0800 (PST) Received: from x1.com ([142.188.210.156]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8b2af042c9csm1444759485a.46.2025.11.19.09.29.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 09:29:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763573361; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z/qhRlrhL2hHAQxy9Ba9VBELeFSbko3iP9NyeeHVbJY=; b=OStvHX41ML+1xD5TBEzL9CC3DUNj/LMp2d7Zq+2/VjGQZa8gbVJET71wJ8+OTei8sI0IHv eC3XPeTnUG5piRTeZE5nHk64NXTeYDLxl7dEXkp9J/2q/AKUHawbxwTNudRoyEYCE1HkYb 0ZOZLptX741EaLUFHcnHTUe3aQL9kB8= X-MC-Unique: 7kpSR_5VO6qrTFbNrR6weg-1 X-Mimecast-MFC-AGG-ID: 7kpSR_5VO6qrTFbNrR6weg_1763573359 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763573359; x=1764178159; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=z/qhRlrhL2hHAQxy9Ba9VBELeFSbko3iP9NyeeHVbJY=; b=gJeENwYj48a27/q4DmsE0Jcbu+kr+Nync3v9eQo/LD8mcrM6HXr4BAiuE/40/tvGAh 1ZdmkpjmIEHKwt1i9dRTxTPZ5lem19km8IG8obLOfxPm8FhZxsWtTklf39f64LvJCWK0 T3UIKyCkroAHEv3+nDyVFKcKFeqB+xcAjOx78vwm37FWMakOEaCGJTqV/N7eaZbQumad 0VEoPbFrcEJYiLCzLlB5DpK5iloKw4ekaAizTII0rzVPQ0PNb6a26IEB5n+uiYctdifP r1QWANIOkcGgFYiSy+Tg1okGdvBXN66xsfZEGddL7fc5TJ+K6XuKdagaYXq6lXC1hEpJ JhSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763573359; x=1764178159; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=z/qhRlrhL2hHAQxy9Ba9VBELeFSbko3iP9NyeeHVbJY=; b=ueyMQgh1yB0sKdzEbGo74UUlyxICHjGf9sZwaIf5KsmE2Hql90LUrUNgYeOQoPmPkr l/lRndB2bvIT4YNAcWmVWzPEVa5g+aKmT/X6s3QIp2rf7/1GnjlCOwIxNohD1BjG0eRU RrIjJLoOZ5ET7254F0tZBzATtDXHBhtBomBUx+MMRtQrgyWvelmAf33RtXbKs8hYAkqB J5nhyFMx8f2dkB7P3+hYpVRfP6v54P/8Q14JOFpa8fl2gIn98zzsjg0hg5Q47PB02FhF PSiPYYulKIKWd9edSNTot8/f2y+LeZwxs/L07Z0xUuux0rvDjnqEx+v+eotKLZ7TlsKR oNfw== X-Gm-Message-State: AOJu0YxziUVGCw1iAuI0kh9NCVmo73+v0fjnDOgobELO8fdA/6bHzgi0 yQ1Z2m7qSkboH30U1C4ccmXFnOgcas+IkpIm3/NPaMGBR9hHHM7YS8DSez9iG5NwL7ro2EroCrq grKXJlZJ6G0gRxoIia6ChNMXk4d9A6uXBZp9h+APvUdN0FDPKHLJ7cqiP5FYfIg1twuy8VnqBWj zQw8MThNehmYwDm0c654LBFxz8EllaD5bwxuaiWw== X-Gm-Gg: ASbGncs8ggWL4HR3GKmGIXN7VEhVGzT2BJPoJC2GwcwGAkKrbSLnkg5mPeJFRYUZcF4 3BZFv5viapU4zgHKdlbbWHXQv7S4yFfxnvAdvWsbbpADaTDmndzk22nrPrI6qqxH0y9ZvueFTkz 3BiInknsjrLfGOQ7vJAWhgkOHRwBQ1KhSdvXaLmoAT5vCfUTWwg+xmHHSkk425qd2XR/WKzZ3B8 kGKbV6/D9h8DYg0meZOaZCcQdaTLAYewSOkvRa4RnGQ+OgUrprBLVkfN+ht9e5asYndNdEM2eQc 6s3Axym9Hr9wuUgMq+sxKoWsmrr9HDd4YXiUnLS7j0N85Mi/r34xTW2tK7CAxAmH3Dmb/C8D5xt l X-Received: by 2002:a05:620a:4443:b0:8b2:dfda:66c4 with SMTP id af79cd13be357-8b3271f3baemr23463085a.8.1763573358969; Wed, 19 Nov 2025 09:29:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IFszdwXgXqadTURmKX6GrLjwtuOtx0zhOyJIsiSrNwIISrL//Z08/sOMWieOqZzvOGd2aXZRg== X-Received: by 2002:a05:620a:4443:b0:8b2:dfda:66c4 with SMTP id af79cd13be357-8b3271f3baemr23458285a.8.1763573358441; Wed, 19 Nov 2025 09:29:18 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: Paolo Bonzini , David Hildenbrand , Alexey Kardashevskiy , peterx@redhat.com, Chenyi Qiang , Juraj Marcin , Li Xiaoyao , Fabiano Rosas Subject: [PATCH v2 2/9] kvm: Detect guest-memfd flags supported Date: Wed, 19 Nov 2025 12:29:06 -0500 Message-ID: <20251119172913.577392-3-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251119172913.577392-1-peterx@redhat.com> References: <20251119172913.577392-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1763573467078018900 Content-Type: text/plain; charset="utf-8" Detect supported guest-memfd flags by the current kernel, and reject creations of guest-memfd using invalid flags. When the cap isn't available, then no flag is supported. Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 96c194ce54..f477014126 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -108,6 +108,7 @@ static int kvm_sstep_flags; static bool kvm_immediate_exit; static uint64_t kvm_supported_memory_attributes; static bool kvm_guest_memfd_supported; +static uint64_t kvm_guest_memfd_flags_supported; static hwaddr kvm_max_slot_size =3D ~0; =20 static const KVMCapabilityInfo kvm_required_capabilites[] =3D { @@ -2787,6 +2788,10 @@ static int kvm_init(AccelState *as, MachineState *ms) kvm_guest_memfd_supported =3D kvm_vm_check_extension(s, KVM_CAP_GUEST_MEMFD) && kvm_vm_check_extension(s, KVM_CAP_USER_MEMORY2); + + ret =3D kvm_vm_check_extension(s, KVM_CAP_GUEST_MEMFD_FLAGS); + kvm_guest_memfd_flags_supported =3D ret > 0 ? ret : 0; + kvm_pre_fault_memory_supported =3D kvm_vm_check_extension(s, KVM_CAP_P= RE_FAULT_MEMORY); =20 if (s->kernel_irqchip_split =3D=3D ON_OFF_AUTO_AUTO) { @@ -4492,6 +4497,12 @@ int kvm_create_guest_memfd(uint64_t size, uint64_t f= lags, Error **errp) return -1; } =20 + if (flags & ~kvm_guest_memfd_flags_supported) { + error_setg(errp, "KVM does not support guest-memfd flag: 0x%"PRIx6= 4, + flags & ~kvm_guest_memfd_flags_supported); + return -1; + } + fd =3D kvm_vm_ioctl(kvm_state, KVM_CREATE_GUEST_MEMFD, &guest_memfd); if (fd < 0) { error_setg_errno(errp, errno, "Error creating KVM guest_memfd"); --=20 2.50.1