From nobody Tue May 21 15:53:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1618994260; cv=none; d=zohomail.com; s=zohoarc; b=kJ/Sc1fG3Z8Tec7a+m8+in2NyCunkyYuTWpe97DaIVy+veaelFieK3x8EkFPYL9Jo1Sgf5w1tjUmDMfROS5kkrke/7El7pW0Fi/VprclglQx+l17xoZQrXALvRsFILDSOjjtlj4652NKBciBKbvXu1bTK3CBOB6A+Os6tFH29sI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618994260; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=grPQRj1Ns9EngNZkqXMG9YFkDqy8hd1r5k349KarIj8=; b=nCixEmuf3GhZM+kPWsV17YASVw6YAqU8NTIQqNSW/3C103Sep+cuNZJJX3CIM9IdQ9VeDGGLEi/LQcN+QSHtWTOEKOBeoeJ2tmSEc/C+pv/+sN1cJ9Tq6SzGDzIGqN9kYtE6feMZMVeEz4ia3F841XBVL1SqkfyiwoJxEuXT5Qw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1618994260585871.895842954283; Wed, 21 Apr 2021 01:37:40 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-395--WxhHYe2PiCnQff7oKwzzA-1; Wed, 21 Apr 2021 04:37:37 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5478A10053EA; Wed, 21 Apr 2021 08:37:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B96555D6A1; Wed, 21 Apr 2021 08:37:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BAA5544A58; Wed, 21 Apr 2021 08:37:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13L8QFkq019385 for ; Wed, 21 Apr 2021 04:26:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4D671112D190; Wed, 21 Apr 2021 08:26:15 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 48F4E1121321 for ; Wed, 21 Apr 2021 08:26:12 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5766B183624B for ; Wed, 21 Apr 2021 08:26:12 +0000 (UTC) Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-538-ULs1UGxoNVyVWtWl2zmENA-1; Wed, 21 Apr 2021 04:25:37 -0400 Received: by mail-pg1-f170.google.com with SMTP id y32so29070333pga.11 for ; Wed, 21 Apr 2021 01:25:36 -0700 (PDT) Received: from C02D383UML85.bytedance.net ([139.177.225.251]) by smtp.gmail.com with ESMTPSA id d12sm1358252pjj.50.2021.04.21.01.25.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Apr 2021 01:25:34 -0700 (PDT) X-MC-Unique: -WxhHYe2PiCnQff7oKwzzA-1 X-MC-Unique: ULs1UGxoNVyVWtWl2zmENA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=grPQRj1Ns9EngNZkqXMG9YFkDqy8hd1r5k349KarIj8=; b=fTLi74bGPHdLRj4b+vfhz+G0NAc8Qq5yz2xtgB8MqxLMwaJ0oC7BuPJkcondtKyCrn SpHxqduJmHUllOKjBDVk/p/nD4LBNqutCgM2UnXeHG+ECJLuvcJwgS4n7BOcqn6EvOcj PFIAlgZhwIfenjHGrfMjwro5i4b0SZtR0q3jQ7xJzQ65YYMS1qVarCMJ8Gxnz8qR75SS SQIwV/eQvSHD9PGoCuq0uq4ubwII+hlb8NzodXpaDLDz49UV/5AkAppP/Ik3rl/4ipPu TxUW05keQhMKd+fAFz5ANNS+ryauYvQRxGqZzqYL1/NMsSITindb/Hmm+i7gZS//2ys6 UwZg== X-Gm-Message-State: AOAM533p8RDvPzDsd35SM2mJKKBgPnZ6aqFKbQLGSPv9bOAajGNDo1it SWRWZ1/qoSNFRHELOk/oZJu0Zmg4/2+3OqSj X-Google-Smtp-Source: ABdhPJyyyTuGNTC7+aSdRRGfxKBD3Jz5UOoRCnIwpFGFurULO9geoo9ySUzo70g1gO9ZT1U3X0lsqg== X-Received: by 2002:a63:1b55:: with SMTP id b21mr21191124pgm.160.1618993535443; Wed, 21 Apr 2021 01:25:35 -0700 (PDT) From: yezhiyong To: libvir-list@redhat.com Subject: [PATCH] qemu.conf: add max-ram-below-4g option Date: Wed, 21 Apr 2021 16:25:28 +0800 Message-Id: <20210421082528.96868-1-yezhiyong@bytedance.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Wed, 21 Apr 2021 04:37:27 -0400 Cc: yezhiyong , zhangruien , zhenwei pi X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Limit the amount of ram below 4G. This helps in scenarios like GPU passthrough when the GPA used by DMA device is conflict with the decode window of a host bridge and the address translation request to iommu isn't launched, which causes address overlapping. Note that currently this can be triggered by some abnormal behavior of hardware. In the general case, this option needs to be configured when virtual machines share the same host, which is why using qemu.conf to support per-host configuration. Signed-off-by: yezhiyong Signed-off-by: zhenwei pi Signed-off-by: zhangruien --- src/qemu/qemu.conf | 8 ++++++++ src/qemu/qemu_command.c | 4 ++++ src/qemu/qemu_conf.c | 5 +++++ src/qemu/qemu_conf.h | 1 + 4 files changed, 18 insertions(+) diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf index 8722dc169c..f09c89486e 100644 --- a/src/qemu/qemu.conf +++ b/src/qemu/qemu.conf @@ -898,6 +898,14 @@ # NOTE: big files will be stored here #memory_backing_dir =3D "/var/lib/libvirt/qemu/ram" =20 +# Limit the amount of ram below 4G. This helps in scenarios like +# GPU passthrough when the GPA used by DMA device is comflict with +# the decode window of a host bridge and the address translation +# request to iommu isn't launched, which causes address overlapping. +# Note that currently this can be triggered by some abnormal behavior +# of hardware. +#max_ram_below_4g =3D "2G" + # Path to the SCSI persistent reservations helper. This helper is # used whenever are enabled for SCSI LUN devices. #pr_helper =3D "/usr/bin/qemu-pr-helper" diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2f69a79bc0..fd5e14c500 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6960,6 +6960,10 @@ qemuBuildMachineCommandLine(virCommand *cmd, cfg->dumpGuestCore ? "on" : "off"); } =20 + if (cfg->maxRamBelow4G) + virBufferAsprintf(&buf, ",max-ram-below-4g=3D%s", + cfg->maxRamBelow4G); + if (def->mem.nosharepages) virBufferAddLit(&buf, ",mem-merge=3Doff"); =20 diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 916a3d36ee..b718995870 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -384,6 +384,8 @@ static void virQEMUDriverConfigDispose(void *obj) g_strfreev(cfg->capabilityfilters); =20 g_free(cfg->deprecationBehavior); + + g_free(cfg->maxRamBelow4G); } =20 =20 @@ -1001,6 +1003,9 @@ virQEMUDriverConfigLoadMemoryEntry(virQEMUDriverConfi= g *cfg, g_autofree char *dir =3D NULL; int rc; =20 + if (virConfGetValueString(conf, "max_ram_below_4g", &cfg->maxRamBelow4= G) < 0) + return -1; + if ((rc =3D virConfGetValueString(conf, "memory_backing_dir", &dir)) <= 0) { return -1; } else if (rc > 0) { diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 2f64e39a18..ff558e2fdb 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -216,6 +216,7 @@ struct _virQEMUDriverConfig { bool virtiofsdDebug; =20 char *memoryBackingDir; + char *maxRamBelow4G; =20 uid_t swtpm_user; gid_t swtpm_group; --=20 2.24.3 (Apple Git-128)