From patchwork Mon May 6 12:37:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 795007 Delivered-To: patch@linaro.org Received: by 2002:adf:a453:0:b0:34e:ceec:bfcd with SMTP id e19csp901586wra; Mon, 6 May 2024 05:39:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVDAJ1w5nlDb4pdd7lCiPrvIWHEUxNvGUKu1OOzgwy1Ng2nx7D46gyW1Ezl4bQ1mzQpQYujBMlCQl15iAY/uS+p X-Google-Smtp-Source: AGHT+IFGmgwKPaht/D55Szx/TJpDLhgnc7HZbFfJ5HjlZD3Vds1tgN6BXPzdTmOIwXgZ+xxPN6Vu X-Received: by 2002:a05:620a:29ca:b0:790:c91a:73ae with SMTP id s10-20020a05620a29ca00b00790c91a73aemr25620504qkp.2.1714999191376; Mon, 06 May 2024 05:39:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1714999191; cv=none; d=google.com; s=arc-20160816; b=q8GH8QmFJv5M/x0GAeQ1oKm7zhcnQRUwPUwVbUPNppkNGDH1ds8q7ruet54YQ91+Dv ys5spEMkgXxt0oNpEKvuR7WzNfjqlxlGK2OnVsMQVX4s6G8u8dTRWoWP0EyIVZeKjyHH aAPs8rXhsXIdubKVppNM4WalalqgNwkFkyv8NX8ABS5xIgs3bPtv98by5lySMSIzgejy a2vgqI9t204J2AWk70W73aZCSU5Uq0PuR/A+97rSutnefhqosRFsjPz4CQrpcSxEozMw jKWTh600ctDcSAYjXwXfhS3CILnssQMriSBHHyjbyEaUrm4pNdJIsOhbxcTMAGfsO07F 6eTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=M2dIn65/w/ORbBuM0bD/NrI0A+aMa+5s4kd6JrVU3Ow=; fh=Ea1Ifb+aNA659h3B2Y0Cksei6Mwa0R7RBOGkfNjINlo=; b=W12qhB6PtXjxVtSHrQt8GiDrOkBO+bPlPw0mo+SslpuL2MgS3uJ+8r58B3G2liAVAW uUXrwm9zy13OsXH9KmNybRzDwGMNdrKkBmWTXrjexuxuriYBTFgl5kjPnfOEu+4LFJdd Lna8VTwsdsZXPqedmHJvt1AWKyVm965JSzdoAQMvftlVxggrBXRl0RkW7IcQ8bkZToG0 1KD15qKodBQyATIDtwRrBkgV8zrAuhtxfKW+YtO+9VDsR7Ipsai+0e1XlfzzZPFs1iha mh6aNJlbvybEd5sNOqV4ftWMCUY/yTLGWqsA2fSjeAVSYw0BG+SfLNwG+WJhWpJjL0Wm GRLQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ne9/5zCF"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id pi39-20020a05620a37a700b0079295d7ff11si2676439qkn.321.2024.05.06.05.39.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 May 2024 05:39:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ne9/5zCF"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s3xcz-0004hi-6f; Mon, 06 May 2024 08:39:33 -0400 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 1s3xcv-0004Ak-54 for qemu-devel@nongnu.org; Mon, 06 May 2024 08:39:29 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s3xcr-0002AP-Tq for qemu-devel@nongnu.org; Mon, 06 May 2024 08:39:28 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-41b869326daso12685915e9.0 for ; Mon, 06 May 2024 05:39:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714999163; x=1715603963; 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=M2dIn65/w/ORbBuM0bD/NrI0A+aMa+5s4kd6JrVU3Ow=; b=ne9/5zCF4a6KBoTxso5oiw1IT0sa2um0InHsTdtLsJ4qRxmES+r1vLagCwbG8Hg30S 0U296T7XMfbIKbOt4zrBwc09wI0V0ZOsaDNMf2XJV3mY5H3biL0LIPaZ+DA52a4W3kh3 ENwdn98zXGwN7/1lBhkQeDcs9auHq8n4qDExo6iTaAwKQ/7CfYfQ7a4K7X+adfOe46f4 RIFAIn1KOWN9VlSPWnDX/oj2NZNPs2bvkDfLtvWTPMGNLmzxd7Ix//hjnAIANnf3UCwH BYp8N1VDYKvPPXHfZIwOxFsNkoLw44YXOEODQJArQuFQGkhnlzmqzLkZKqPlK16a/oIs r9qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714999163; x=1715603963; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M2dIn65/w/ORbBuM0bD/NrI0A+aMa+5s4kd6JrVU3Ow=; b=RGwEfhHAldY4TPdlediV2FGzl+OdiLlyW4rgpLzK/3YdTNVcy2QDjD5Tv5kYYpJbC2 MZmX4hBe8vkFXRx0oe046eb85TcMJIpHWfFq7ejm4AZybZjpluyas9OYDNXd3fi4lhpq IEE7N4E4JLabqvstlPwVLB9mY+tVmkNJVgqJv1BSYPIIFojNlleaCI+WKKy47FdJ2vPu T5LYvz+QdzKwqCK4Rg38Kr2mHYDLDAGkMdsYtv0h87yw68Z1sleSZCFdEZzEO5JSyjI9 n4ebNHtr+XebNVQSzVzN6v/9bvf5QEQQzux41+11qnx1Lx+N2ltX0jUJgE9uwL391NUv nh4w== X-Gm-Message-State: AOJu0YxDtAZyv3+BLqbN40DAmEhVK8YcaCS1YY7BhUO1R0PJM1M0X7Wb wKfv51qfBT4wPRw5Yau59di21E0d3ShmBGoyzPHJdh7RxakMbRIc293VmS9K4+O3HMPkNyNTwrj a X-Received: by 2002:a05:6000:1963:b0:34a:d1d4:cb3c with SMTP id da3-20020a056000196300b0034ad1d4cb3cmr9155061wrb.39.1714999163635; Mon, 06 May 2024 05:39:23 -0700 (PDT) Received: from m1x-phil.lan ([176.187.211.4]) by smtp.gmail.com with ESMTPSA id t7-20020a5d6907000000b00349bd105089sm10559984wru.47.2024.05.06.05.39.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 06 May 2024 05:39:23 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Juergen Gross , Vikram Garhwal , Stefano Stabellini , =?utf-8?q?Alex_Benn=C3=A9e?= , "Edgar E . Iglesias" , David Hildenbrand , Peter Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 16/28] softmmu: let qemu_map_ram_ptr() use qemu_ram_ptr_length() Date: Mon, 6 May 2024 14:37:16 +0200 Message-ID: <20240506123728.65278-17-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240506123728.65278-1-philmd@linaro.org> References: <20240506123728.65278-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=philmd@linaro.org; helo=mail-wm1-x32d.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Juergen Gross qemu_map_ram_ptr() and qemu_ram_ptr_length() share quite some code, so modify qemu_ram_ptr_length() a little bit and use it for qemu_map_ram_ptr(), too. Signed-off-by: Juergen Gross Signed-off-by: Vikram Garhwal Reviewed-by: Stefano Stabellini Reviewed-by: Alex Bennée Message-Id: <20240227223501.28475-4-vikram.garhwal@amd.com> Reviewed-by: Edgar E. Iglesias Signed-off-by: Edgar E. Iglesias Acked-by: David Hildenbrand Reviewed-by: Peter Xu Message-ID: <20240430164939.925307-2-edgar.iglesias@gmail.com> Signed-off-by: Philippe Mathieu-Daudé --- system/physmem.c | 56 ++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/system/physmem.c b/system/physmem.c index 44e477a1a5..8278e31c1a 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -2189,43 +2189,17 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) } #endif /* !_WIN32 */ -/* Return a host pointer to ram allocated with qemu_ram_alloc. - * This should not be used for general purpose DMA. Use address_space_map - * or address_space_rw instead. For local memory (e.g. video ram) that the - * device owns, use memory_region_get_ram_ptr. - * - * Called within RCU critical section. - */ -void *qemu_map_ram_ptr(RAMBlock *block, ram_addr_t addr) -{ - if (block == NULL) { - block = qemu_get_ram_block(addr); - addr -= block->offset; - } - - if (xen_enabled() && block->host == NULL) { - /* We need to check if the requested address is in the RAM - * because we don't want to map the entire memory in QEMU. - * In that case just map until the end of the page. - */ - if (block->offset == 0) { - return xen_map_cache(addr, 0, 0, false); - } - - block->host = xen_map_cache(block->offset, block->max_length, 1, false); - } - return ramblock_ptr(block, addr); -} - -/* Return a host pointer to guest's ram. Similar to qemu_map_ram_ptr - * but takes a size argument. +/* + * Return a host pointer to guest's ram. * * Called within RCU critical section. */ static void *qemu_ram_ptr_length(RAMBlock *block, ram_addr_t addr, hwaddr *size, bool lock) { - if (*size == 0) { + hwaddr len = 0; + + if (size && *size == 0) { return NULL; } @@ -2233,7 +2207,10 @@ static void *qemu_ram_ptr_length(RAMBlock *block, ram_addr_t addr, block = qemu_get_ram_block(addr); addr -= block->offset; } - *size = MIN(*size, block->max_length - addr); + if (size) { + *size = MIN(*size, block->max_length - addr); + len = *size; + } if (xen_enabled() && block->host == NULL) { /* We need to check if the requested address is in the RAM @@ -2241,7 +2218,7 @@ static void *qemu_ram_ptr_length(RAMBlock *block, ram_addr_t addr, * In that case just map the requested area. */ if (block->offset == 0) { - return xen_map_cache(addr, *size, lock, lock); + return xen_map_cache(addr, len, lock, lock); } block->host = xen_map_cache(block->offset, block->max_length, 1, lock); @@ -2250,6 +2227,19 @@ static void *qemu_ram_ptr_length(RAMBlock *block, ram_addr_t addr, return ramblock_ptr(block, addr); } +/* + * Return a host pointer to ram allocated with qemu_ram_alloc. + * This should not be used for general purpose DMA. Use address_space_map + * or address_space_rw instead. For local memory (e.g. video ram) that the + * device owns, use memory_region_get_ram_ptr. + * + * Called within RCU critical section. + */ +void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr) +{ + return qemu_ram_ptr_length(ram_block, addr, NULL, false); +} + /* Return the offset of a hostpointer within a ramblock */ ram_addr_t qemu_ram_block_host_offset(RAMBlock *rb, void *host) {