From nobody Tue May 14 20:32:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1695057421; cv=none; d=zohomail.com; s=zohoarc; b=fBep/j4g9mMEdhJQ323nUbGjy9274YEcw+bq6nPGHZxRV7VfXpONddLS4MXN4OHpao5dd0XluEy99mscW0JplL7huWJQ/HYZ7aj8Z/0mRoWCBkiqhhDVs42v0xRBwFuGCafMxxA1j1RAw14uDxx+v+N14AWDrQkWgMVaehsvsmo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695057421; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=O5NUtt6vrkzT3bl6QM5bm/yicPtunw2wr1Hm1++f5hk=; b=Tk/rtrNUVnBDrVbNsyJGT+D5neX2HcFsVoUFF2bOu9CChH2n9uDFsepxnYh9KWVCGLdTin25DCibpCjcvqrEVNf2ByYK3D6GL0U3dXeLKn6Otc8zSJrzwxgSHW3pAxk+bYyeR3xiUvD2gyX0HD1SpFCLSxaLV5NtlCesv/Nmwy4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=quarantine) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1695057421562133.46624007373998; Mon, 18 Sep 2023 10:17:01 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-207-atjcnt8fM5ut7FWQB0Sv2Q-1; Mon, 18 Sep 2023 13:16:52 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 C01B885A5BA; Mon, 18 Sep 2023 17:16:49 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 834212156702; Mon, 18 Sep 2023 17:16:47 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 10D11194658D; Mon, 18 Sep 2023 17:16:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BEA7C194658C for ; Mon, 18 Sep 2023 17:16:46 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A1B662156702; Mon, 18 Sep 2023 17:16:46 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast07.extmail.prod.ext.rdu2.redhat.com [10.11.55.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 99A1F2156701 for ; Mon, 18 Sep 2023 17:16:46 +0000 (UTC) Received: from us-smtp-inbound-delivery-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 7955A3C02B2B for ; Mon, 18 Sep 2023 17:16:46 +0000 (UTC) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2064.outbound.protection.outlook.com [40.107.20.64]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-444-RHxRS8THOeCHmebzyzJlCw-1; Mon, 18 Sep 2023 13:16:43 -0400 Received: from PAXPR04MB8623.eurprd04.prod.outlook.com (2603:10a6:102:21a::11) by AM7PR04MB6822.eurprd04.prod.outlook.com (2603:10a6:20b:108::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Mon, 18 Sep 2023 17:16:41 +0000 Received: from PAXPR04MB8623.eurprd04.prod.outlook.com ([fe80::2366:be:c6f3:695f]) by PAXPR04MB8623.eurprd04.prod.outlook.com ([fe80::2366:be:c6f3:695f%5]) with mapi id 15.20.6792.026; Mon, 18 Sep 2023 17:16:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695057420; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=O5NUtt6vrkzT3bl6QM5bm/yicPtunw2wr1Hm1++f5hk=; b=N/vhHh9/hKq1zv1oHeYaXGmRWNndrPkkcWduRBmLj6eEXUwgo82RaEWPaJ5v6yDok6FiJU mkSYA9TTlFmyQE835yjloWLzBWSDNHeNPpqfHRl3kU43oS2E231hBtBd1VXVe1mYpUQOvI vvBGkefZXvlhZ+jPczN2ZFEJ+2nPazg= X-MC-Unique: atjcnt8fM5ut7FWQB0Sv2Q-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: RHxRS8THOeCHmebzyzJlCw-1 From: Jim Fehlig To: libvir-list@redhat.com Subject: [PATCH] libxl: Fix Domain-0 ballooning logic Date: Mon, 18 Sep 2023 11:16:23 -0600 Message-ID: <20230918171635.18470-1-jfehlig@suse.com> X-ClientProxiedBy: CY5PR22CA0046.namprd22.prod.outlook.com (2603:10b6:930:1d::28) To PAXPR04MB8623.eurprd04.prod.outlook.com (2603:10a6:102:21a::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8623:EE_|AM7PR04MB6822:EE_ X-MS-Office365-Filtering-Correlation-Id: 9215d2a2-db1c-41e6-f2a8-08dbb86b0672 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0 X-Microsoft-Antispam-Message-Info: ELmuQimExgEVMo3mED1vVrjLNlI4DzmYuzO915uLulYkPoFqo3e/aVjtSrqSocKJwriP1DG9DKMTlgGnDZCxiOBTb1aOtK7Tro1uNeRSjLQ5TOR8pvzYRTfZk9fdgGT5u5dxHg77LgOzMNZeGccxycYKBLmlWSrJtjMLu0Lr/Zt7Mj4jqu1z8JXlQAaqktH0PkP5piMp6iCWWdrWxr0traTFAaAL2w85vUbkZCMaYZwmHR7xPDBKCjbAq9hJ6HsYZcw3fUGq3prJsPh42YZzc6+FPOleyi2KsFYQ/tyC5VeJ9CF2KPN0yM+tE8SFHlluuAGnn2li6bdJIVtzAncFcKtvuSgAIivrG/54+s2vbrZELvdZNhuGM8zdtHjew17HoZdsD/Om6pid1Llkzlbe23bcJ7cFDiBL904GpeCLAZqxDTugSLXX/ZJ0wdjNhzbvzBF23nQyUGrJiwtCnHGWmvBhp8e97uBS4FsosmkFJs8Bn+UBBpBpfqMk9crl+cOt1IxJbhs8UY/avsvOHXg4crFovJWjI3LyJnonA5Fcs2HvOxLdUWGcanQqzSyVRbis X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR04MB8623.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(136003)(376002)(346002)(396003)(366004)(39860400002)(186009)(1800799009)(451199024)(6512007)(6486002)(38100700002)(6666004)(1076003)(66946007)(2616005)(66556008)(66476007)(6506007)(478600001)(83380400001)(86362001)(26005)(2906002)(5660300002)(6916009)(36756003)(316002)(41300700001)(8676002)(8936002); DIR:OUT; SFP:1101 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?+YktiVT07ancCbSClAGLVpcsgfRuW01H2Zt3hw9LnODcZgOeIim+ka0dG5JV?= =?us-ascii?Q?45me4i9MaEgKSkL363l5o85xSasslr2GYsyYgNA+XvwiuAxiezbtBism8Se9?= =?us-ascii?Q?MP2pmpPZkpSu7/XDBKCrZVm+B7bwH9BbBl+BttKH2zS2CyZkgbzQmPrxgBkX?= =?us-ascii?Q?SMtVb0DRgtqXNYkIP7EAjJADQWphyNcJyVzlVAxWiecXT+bWAMKZKVD7Tu/P?= =?us-ascii?Q?e7+g3p8VcYDTf037ogYBJ49bSRmursdCi/BA+Q+kW3gxmKtA2rpgyItnlowM?= =?us-ascii?Q?csSqZu5T0VUEG3f+graorFkZ1mHX0LbzU9RDyqI8nnY644TkUMcMoN+m8bch?= =?us-ascii?Q?SKP/Zgr+WCv1WH7SeMhJjXlfiwUjVKOxEToGUGKpT87Qk6kOyOYRsqa+3SZx?= =?us-ascii?Q?HaoL9qEKXG4iDoEBn0jEw3atoqMF2icYLpf1HhF/1Bxj4mjBKsKpdwC/iOG4?= =?us-ascii?Q?2toqGZxSQytdERX+YXkTuWNvMOC1HW0YWdMt4JLklPvkW9zWJudWuVDxwhdT?= =?us-ascii?Q?mei1VYZDKdigSg/LygNOWXXOe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XdNGEef3dsec1KNprdiN7otMA3Bm0HLv5jNkG9xRc4/9uzGidnNJXwMIlz?= =?us-ascii?Q?5IJ1x8fgouhy0vb10tmcq1cpi7K+3N0r8vhn095Mtzx6ohyx+RMEWDA1QDQM?= =?us-ascii?Q?aU/f70IzAHJ09rrq6z2WkmxjQ99HQmfIDNccd32S?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9215d2a2-db1c-41e6-f2a8-08dbb86b0672 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8623.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 17:16:41.3876 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QFadZSHsmJK5WXxD4fhEgUyLaHeo1TVJ3T6QoZ6JutIB7HDic6M4SeQUsFUJuY+0WglJCWxXV7chh4wgJ06bGw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB6822 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 3.1 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695057423372100001 Content-Type: text/plain; charset="utf-8" When Domain-0 autoballooning is enabled, it's possible that memory may need to be ballooned down in Domain-0 to accommodate the needs of another virtual machine. libxlDomainFreeMemory handles this task, but due to a logic bug is underflowing the variable containing Domain-0 new target memory. The resulting huge numbers are filtered by libxlSetMemoryTargetWrapper and memory is not changed. Under the covers, libxlDomainFreeMemory uses Xen's libxl_set_memory_target API, which includes a 'relative' parameter for specifying how to set the target. If true, the target is an increment/decrement value over the current memory, otherwise target is taken as an absolute value. libxlDomainFreeMemory sets 'relative' to true, but never allows for negative values by declaring the target memory variable as an unsigned. Fix by declaring the variable as signed, which also requried adjusting libxlSetMemoryTargetWrapper. Signed-off-by: Jim Fehlig Reviewed-by: Michal Privoznik --- src/libxl/libxl_api_wrapper.h | 16 ++++++---------- src/libxl/libxl_domain.c | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/libxl/libxl_api_wrapper.h b/src/libxl/libxl_api_wrapper.h index a9627f7983..c9582294cc 100644 --- a/src/libxl/libxl_api_wrapper.h +++ b/src/libxl/libxl_api_wrapper.h @@ -193,24 +193,20 @@ libxlSendTriggerWrapper(libxl_ctx *ctx, static inline int libxlSetMemoryTargetWrapper(libxl_ctx *ctx, uint32_t domid, - uint64_t target_memkb, + int64_t target_memkb, int relative, int enforce) { int ret =3D -1; =20 - /* Technically this guard could be LIBXL_HAVE_MEMKB_64BITS */ -#if LIBXL_API_VERSION < 0x040800 - if (target_memkb < UINT_MAX) { - uint32_t val32 =3D target_memkb; +#ifdef LIBXL_HAVE_MEMKB_64BITS + ret =3D libxl_set_memory_target(ctx, domid, target_memkb, relative, en= force); +#else + if (target_memkb < INT_MAX) { + int32_t val32 =3D target_memkb; =20 ret =3D libxl_set_memory_target(ctx, domid, val32, relative, enfor= ce); } -#else - if (target_memkb < LLONG_MAX) { - int64_t val64 =3D target_memkb; - ret =3D libxl_set_memory_target(ctx, domid, val64, relative, enfor= ce); - } #endif =20 return ret; diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 6c167df63e..0c4beffd6a 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -926,7 +926,7 @@ libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config = *d_config) { uint64_t needed_mem; uint64_t free_mem; - uint64_t target_mem; + int64_t target_mem; int tries =3D 3; int wait_secs =3D 10; =20 --=20 2.42.0