From patchwork Tue Apr 30 16:49:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649662 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1AF7C19F4F for ; Tue, 30 Apr 2024 16:51:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qgh-0006Ui-Gh; Tue, 30 Apr 2024 12:50:41 -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 1s1qgJ-00062K-Of for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:16 -0400 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgH-00060m-OY for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:15 -0400 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-51b09c3a111so8378050e87.1 for ; Tue, 30 Apr 2024 09:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495810; x=1715100610; 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=O5hYPezHo/zUw5sp2oiFt2YbldZcwf6wRos1WLmtnWI=; b=Rm11UI1BoWEfe7ajRuKPHBfO0W1fP1WNjyAwjfC+isJhCxxiXxRWlAkoOAT/IrnJoj xyTs6SQNuRu32rov3hCe31OzYzVykwGlnveO3El0ksE3It1r7/BgibkZjLdBk3KbnbyG mpUibJi4Awc+HhaXiNNkE+AfQb7mVQsxElpyfAhR1fmz045xHlq7nuoAapXjnmPrWGfJ dsXg3Ruzns6GQ+1R7t1T+pTsl5+1UB0wzAgHOeqW0hfkZpxP7ZEWGPlTGASNM01XiwrK sX14kjbjh0wgeJB/LHHlNQS/mKB39TKHwnRJF8ZonLOHK11TxxzgiYmFa6DpJSNghRO3 JZGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495810; x=1715100610; 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=O5hYPezHo/zUw5sp2oiFt2YbldZcwf6wRos1WLmtnWI=; b=qQz741ISNpQzAq2Kg7+/C3lLrlBZi+iSTmBxzBKZKCf16b97q/ohgzebxG0Bh8rmGF gxgNppNo4oeOnR7w8hk1QZrHTUvKuMU7ekwBM9CbdjnZVRrChGsJ45tLI9Tbm89TyNtu UCuamSyipbn+5Jz1jL04ykIWxfjwRyo3PpnFAiqtaMlEwokbWBVj5bBV8ha0qr0aX8W8 9oYRCXjaVJTkr4bKz1QiQ93lMj/tx6EKwL7pkPNEhqc8DFca7DAP8vLFRRUrXVFZ5GYe T8W2G/u+XftPj7gXGUTN1fiY8nT/8UsgvNVpFEUycr0v5E4EjQ4PLt5AlGHB7c/k9qIp a+PA== X-Gm-Message-State: AOJu0Yz5jFWAYjNdBLZCZRGrwXx6JO9UK+bb8jcF9rKwkhrTkjX1Iim9 oLmyGHJu5hhuGlWqfhfDqpJOyrQh2rxt9zrIBEPctK7hbe4MUGuJl1MiUMpV X-Google-Smtp-Source: AGHT+IEu2vlNQZuUjLrZbAElRgF9mqW1BA23HN64n4+WENNqRodrErKRabxZXDwUC9luBsb2kGGndA== X-Received: by 2002:a05:6512:3f21:b0:51d:8159:598 with SMTP id y33-20020a0565123f2100b0051d81590598mr35777lfa.19.1714495809996; Tue, 30 Apr 2024 09:50:09 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id k8-20020a192d08000000b0051ac9a297aasm4096722lfj.141.2024.04.30.09.50.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:08 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, Vikram Garhwal , "Edgar E . Iglesias" , =?utf-8?q?Alex_Benn=C3=A9e?= , Paolo Bonzini , Peter Xu , David Hildenbrand , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v4 01/17] softmmu: let qemu_map_ram_ptr() use qemu_ram_ptr_length() Date: Tue, 30 Apr 2024 18:49:23 +0200 Message-Id: <20240430164939.925307-2-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::129; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x129.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, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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 Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini Reviewed-by: Alex Bennée Reviewed-by: Edgar E. Iglesias Acked-by: David Hildenbrand Reviewed-by: Peter Xu --- system/physmem.c | 56 ++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/system/physmem.c b/system/physmem.c index 1a81c226ba..f114b972a5 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -2188,43 +2188,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; } @@ -2232,7 +2206,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 @@ -2240,7 +2217,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); @@ -2249,6 +2226,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) { From patchwork Tue Apr 30 16:49:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649676 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B0CBAC4345F for ; Tue, 30 Apr 2024 16:52:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qgm-00070w-7M; Tue, 30 Apr 2024 12:50:44 -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 1s1qgM-00065g-Tr for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:18 -0400 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgL-000613-5i for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:18 -0400 Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-516d4d80d00so7533226e87.0 for ; Tue, 30 Apr 2024 09:50:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495814; x=1715100614; 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=fwamhPCUJY+N7YTIaqBuMDMNKLfZW1hiEtgPXWAFdNA=; b=KHu8E7Ce3mzwBSP6a12asR/K7jlppdxkI3tLleB/xYy4PkNQ+yQVotHXda2CuCa8wt Zys0CTE2f6CUaQV9quzqkSpHjteOxjo9BcWa2hSq81v4udc76KUGP3cbifpM0DckJutn c6e7VMA85fsVwrkKG+69Hpc1OsGzL6ICrZZ22j79PZvs0djzxVKBt8EpSEYZFzHgNgFa TMSS20DkBHMXs1ty9yPkTYj1IHr/D6C78AOFxo8TJWTWqBMnZvvampFhyvXh6qWq3eru HLbotiVsTbnw8dGLsRBBYbaPpjWPgOxH1eFhUXAuAUp8CJpqwuLqyZu4D27DS5U1VUPw 7uow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495814; x=1715100614; 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=fwamhPCUJY+N7YTIaqBuMDMNKLfZW1hiEtgPXWAFdNA=; b=MxuNycirDClUFwcIoaWMH0mX9qQ7Y9fYrkPKSyqxxA0rIQvn26StXVyxU8QSI0qlnd dovbFSaGPWW6DHtsufJvFN4nJuATGZy2w0QuI1htp6FOl7eM9MXHzTDBDf6JeUvJjg4m Gz6ID8foNLTD36nh8CaAvgdy/lQkujfSRAdp2Rcfm9Pe+2QC35YR1hNNL3ywJXptRJW8 VerKvkU16TcDMqiNHoXH3UF2xaKy8tA2d12oxsHoiFWxPCkwXpk9XDLKtav76VxluXaD bbMI9BJqb8bq8zxUZvMrpFMz0TXfB9+cDUEF5fCVuHHGI9nZQ0tEHB26YqdB3t+AA/nK 8o3A== X-Gm-Message-State: AOJu0Yw+au6n1tyPKXnHl3hdycNnMi+JNQRQlJDOjwv5zBWmyvoSq/mm D170GM0vNHurSGq/VdeE9Zy+uLe7dMFKsWUB1EKaHIUOAkQV3GGXDQ0gB9i+ X-Google-Smtp-Source: AGHT+IHoJlSMsC6sfM5UXupD/S6braHFg22PmZ7CRhw+67o7aWoTbAdWexTYOX7plCeimOm047+9GQ== X-Received: by 2002:ac2:5a5b:0:b0:519:6a93:ed3a with SMTP id r27-20020ac25a5b000000b005196a93ed3amr25393lfn.23.1714495812082; Tue, 30 Apr 2024 09:50:12 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id g5-20020a19e045000000b0051bf283570dsm2372896lfj.254.2024.04.30.09.50.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:10 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E . Iglesias" , =?utf-8?q?Alex_Benn=C3=A9e?= , Anthony Perard , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v4 02/17] xen: let xen_ram_addr_from_mapcache() return -1 in case of not found entry Date: Tue, 30 Apr 2024 18:49:24 +0200 Message-Id: <20240430164939.925307-3-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12e; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x12e.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, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Juergen Gross Today xen_ram_addr_from_mapcache() will either abort() or return 0 in case it can't find a matching entry for a pointer value. Both cases are bad, so change that to return an invalid address instead. Signed-off-by: Juergen Gross Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini Reviewed-by: Alex Bennée Reviewed-by: Edgar E. Iglesias --- hw/xen/xen-mapcache.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index 7f59080ba7..b7cefb78f7 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -394,13 +394,8 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr) } } if (!found) { - trace_xen_ram_addr_from_mapcache_not_found(ptr); - QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) { - trace_xen_ram_addr_from_mapcache_found(reventry->paddr_index, - reventry->vaddr_req); - } - abort(); - return 0; + mapcache_unlock(); + return RAM_ADDR_INVALID; } entry = &mapcache->entry[paddr_index % mapcache->nr_buckets]; @@ -409,7 +404,7 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr) } if (!entry) { trace_xen_ram_addr_from_mapcache_not_in_cache(ptr); - raddr = 0; + raddr = RAM_ADDR_INVALID; } else { raddr = (reventry->paddr_index << MCACHE_BUCKET_SHIFT) + ((unsigned long) ptr - (unsigned long) entry->vaddr_base); From patchwork Tue Apr 30 16:49:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5DF50C4345F for ; Tue, 30 Apr 2024 16:52:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qgm-00070i-4d; Tue, 30 Apr 2024 12:50:44 -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 1s1qgP-0006D7-H3 for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:23 -0400 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgM-00061B-LF for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:20 -0400 Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2dae975d0dcso72618391fa.1 for ; Tue, 30 Apr 2024 09:50:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495816; x=1715100616; 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=CIVDaUdlQrWMVCAAwSwRQuE7c0313SXxgYK41vL15nU=; b=WGHc1IOHdKp6ljtNS/SNsLAJGk6Qb8uw7+EnTkqeppp6fqRXtdb4ZnMtwN4oZQa6kx JNEndBQiXcUYtHXrpeabUa7FOMYzdg7+9wPfHsFaZ1EuCMJCZcgZP/pywqSpZIZJNm5R fRzXPfpJsgI6q8jb3sp3csDdaBGJ0nqxVNzamOXPX1/G4IFNYJpqVhXEP2mM7DkVkcw2 zz6SgTtyRAcgVjI5/V/q0CUNY50PdZ7zLjqLiy7HoVZ/d3W5qDMBG4TCUeE2IJGf86Lh 2ytuCJc5kOxZW9wvYSe8ooscOHjKfvVrGdXBinMzk1dzc/PKK+FcNIju9wZduU8j3pQ2 ZJRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495816; x=1715100616; 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=CIVDaUdlQrWMVCAAwSwRQuE7c0313SXxgYK41vL15nU=; b=hT6PhfiuM5b+qK3HuOcT4Rvhy3+LpmUtrQwCWuL4tV1UhNU5Ipv4bdd98tB7fr20jH HZmLfTzYkvZLkUvzdYaeXG2OiVcSW0Xb/NSC3CQBiwKUnrQ2aJbcm32Kbfyp9nbtkSJW ygimL5oAbf6/iOivKYXAdIq7YkSHpbWkBwYWgQwhlq+Wg8HrpmITYSyZqYkzd+ORIhCi WGG2awPxYnkRoJma9C2XUTIGmcQJQNEkPrvine0jiPo1/7v2mjfzOeuM611AnV1hSWRr vIRNsho/wGYwM+uXc02akYPUnlfx0Fpy4qge4DoR2juobLotOfFj15I0upVpizxsXpxR g7ZQ== X-Gm-Message-State: AOJu0YylP1xqEbQR4xOlMObFivTMbwyWqEIKhhYGsbGzhoJBgsFS9F3Q k39BtpKseVTXUzthqoC9cZD7TV00gv5MTiE8tMi8j+ZHLWc2KebfWtsCRKet X-Google-Smtp-Source: AGHT+IEhqhmi+/uuFz1Fbog5DE/AV1r+HDsD1UwlwkpNuWJf7wobBS9AqtJFN1Xw/CHLkbbpd70bvw== X-Received: by 2002:a2e:bc0a:0:b0:2d8:4c1d:10fc with SMTP id b10-20020a2ebc0a000000b002d84c1d10fcmr1419744ljf.18.1714495816046; Tue, 30 Apr 2024 09:50:16 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id w18-20020a2e9992000000b002d43737e2d7sm4149404lji.30.2024.04.30.09.50.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:14 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony Perard , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v4 03/17] xen: mapcache: Refactor lock functions for multi-instance Date: Tue, 30 Apr 2024 18:49:25 +0200 Message-Id: <20240430164939.925307-4-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22f; envelope-from=edgar.iglesias@gmail.com; helo=mail-lj1-x22f.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, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Edgar E. Iglesias" Make the lock functions take MapCache * as argument. This is in preparation for supporting multiple caches. No functional changes. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini Reviewed-by: Philippe Mathieu-Daudé --- hw/xen/xen-mapcache.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index b7cefb78f7..3f11562075 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -74,14 +74,14 @@ typedef struct MapCache { static MapCache *mapcache; -static inline void mapcache_lock(void) +static inline void mapcache_lock(MapCache *mc) { - qemu_mutex_lock(&mapcache->lock); + qemu_mutex_lock(&mc->lock); } -static inline void mapcache_unlock(void) +static inline void mapcache_unlock(MapCache *mc) { - qemu_mutex_unlock(&mapcache->lock); + qemu_mutex_unlock(&mc->lock); } static inline int test_bits(int nr, int size, const unsigned long *addr) @@ -369,9 +369,9 @@ uint8_t *xen_map_cache(hwaddr phys_addr, hwaddr size, { uint8_t *p; - mapcache_lock(); + mapcache_lock(mapcache); p = xen_map_cache_unlocked(phys_addr, size, lock, dma); - mapcache_unlock(); + mapcache_unlock(mapcache); return p; } @@ -384,7 +384,7 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr) ram_addr_t raddr; int found = 0; - mapcache_lock(); + mapcache_lock(mapcache); QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) { if (reventry->vaddr_req == ptr) { paddr_index = reventry->paddr_index; @@ -394,7 +394,7 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr) } } if (!found) { - mapcache_unlock(); + mapcache_unlock(mapcache); return RAM_ADDR_INVALID; } @@ -409,7 +409,7 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr) raddr = (reventry->paddr_index << MCACHE_BUCKET_SHIFT) + ((unsigned long) ptr - (unsigned long) entry->vaddr_base); } - mapcache_unlock(); + mapcache_unlock(mapcache); return raddr; } @@ -480,9 +480,9 @@ static void xen_invalidate_map_cache_entry_bh(void *opaque) { XenMapCacheData *data = opaque; - mapcache_lock(); + mapcache_lock(mapcache); xen_invalidate_map_cache_entry_unlocked(data->buffer); - mapcache_unlock(); + mapcache_unlock(mapcache); aio_co_wake(data->co); } @@ -498,9 +498,9 @@ void coroutine_mixed_fn xen_invalidate_map_cache_entry(uint8_t *buffer) xen_invalidate_map_cache_entry_bh, &data); qemu_coroutine_yield(); } else { - mapcache_lock(); + mapcache_lock(mapcache); xen_invalidate_map_cache_entry_unlocked(buffer); - mapcache_unlock(); + mapcache_unlock(mapcache); } } @@ -512,7 +512,7 @@ void xen_invalidate_map_cache(void) /* Flush pending AIO before destroying the mapcache */ bdrv_drain_all(); - mapcache_lock(); + mapcache_lock(mapcache); QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) { if (!reventry->dma) { @@ -546,7 +546,7 @@ void xen_invalidate_map_cache(void) mapcache->last_entry = NULL; - mapcache_unlock(); + mapcache_unlock(mapcache); } static uint8_t *xen_replace_cache_entry_unlocked(hwaddr old_phys_addr, @@ -606,8 +606,8 @@ uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr, { uint8_t *p; - mapcache_lock(); + mapcache_lock(mapcache); p = xen_replace_cache_entry_unlocked(old_phys_addr, new_phys_addr, size); - mapcache_unlock(); + mapcache_unlock(mapcache); return p; } From patchwork Tue Apr 30 16:49:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649681 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9D42EC4345F for ; Tue, 30 Apr 2024 16:53:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qgn-0007BU-5o; Tue, 30 Apr 2024 12:50:45 -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 1s1qgW-0006Hb-0I for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:33 -0400 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgO-00061W-3l for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:26 -0400 Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2dac77cdf43so75645201fa.2 for ; Tue, 30 Apr 2024 09:50:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495818; x=1715100618; 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=RRQG1XAsOj2ShCk3Z8R9KMtS/JhvbfkQx/NMqL6gExE=; b=EKM35OAFJXEY/g+jP9YcjXauR+8VkQGvxY9Pt2kxrd0ek1BoAixxN57DyeMyeMqQkU tJsksAb8giPDinmHXRfHIqpxR43yT+hCNgdFiaD3u1sZvr6SK4uI+vh5wmEy9iGINccj Z+Cs8PrY2vw02XRg7LPpgPqzmWpgiR0xA8dc3AzFWqzyD2ZaysQwJZgSXhaEMI6TKiH8 O/UuyjEKlIpYgFKCUG50yzG5g7wX814Yfztk2UUyj/XRsmJL0djVAIFsL0Xm1tP/syNP XyD3HKCTvUOCxuvBiRPHPvEBN8nlY4X86acbYSeXzpoc9zM+IV1by2NPyBiLe5BiXp4x LwJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495818; x=1715100618; 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=RRQG1XAsOj2ShCk3Z8R9KMtS/JhvbfkQx/NMqL6gExE=; b=dCPbVn+/wKo0eWpuTIcowsJjT8U52GEjrDBN3ATRpl383S57dLqRpK0FZodSb+tmrV fQtW/XPqnjBDBswf9PR9HctpUtUANSg3vpKM9NBsGb1AuQ+JUxayQ5niUzdB7SBbCsZk sLKYikPOPnCc6mk0RIdPFY5yUqnpl7ruai8gmRa1fBcijABru+J6Y05M/2YpJGhoqyXx P2wz+jjUdIdnea5EYYuhxY89cjEV4kNrouAVk30WxkSvffyAmcaTCdMfX9shKhEoEu3v xUKhOqavBzJsrl2Icwhpo05LUvxPqREZLpgtBoUbxP/7+ddDoMXoWYbgTsZJlIDyktC3 xupQ== X-Gm-Message-State: AOJu0YxyHcyaLZdzDfIHDFPdyy6KOpnBhwDk6E8fUrr1hoN8Hf7xZLNO uhuTg6mo3vNFuCOhc2VzDV/CIqmSQNjdyNYVCLX8yv9BHJE251o2IUNhneOR X-Google-Smtp-Source: AGHT+IE34gVM99Avj5+WmVE3KuiSoituQU+AW25n3ZdTsIBUm8HTeWHDkI6iQxAgmbV9XWek/HUgxw== X-Received: by 2002:a2e:9516:0:b0:2d8:63a2:50d2 with SMTP id f22-20020a2e9516000000b002d863a250d2mr213248ljh.6.1714495817622; Tue, 30 Apr 2024 09:50:17 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id b20-20020a2e8954000000b002de1f99164csm2505323ljk.59.2024.04.30.09.50.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:16 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony Perard , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v4 04/17] xen: mapcache: Refactor xen_map_cache for multi-instance Date: Tue, 30 Apr 2024 18:49:26 +0200 Message-Id: <20240430164939.925307-5-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22b; envelope-from=edgar.iglesias@gmail.com; helo=mail-lj1-x22b.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, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Edgar E. Iglesias" Make xen_map_cache take a MapCache as argument. This is in prepaparation to support multiple map caches. No functional changes. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini Reviewed-by: Philippe Mathieu-Daudé --- hw/xen/xen-mapcache.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index 3f11562075..896021d86f 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -240,7 +240,8 @@ static void xen_remap_bucket(MapCacheEntry *entry, g_free(err); } -static uint8_t *xen_map_cache_unlocked(hwaddr phys_addr, hwaddr size, +static uint8_t *xen_map_cache_unlocked(MapCache *mc, + hwaddr phys_addr, hwaddr size, uint8_t lock, bool dma) { MapCacheEntry *entry, *pentry = NULL, @@ -269,16 +270,16 @@ tryagain: test_bit_size = XC_PAGE_SIZE; } - if (mapcache->last_entry != NULL && - mapcache->last_entry->paddr_index == address_index && + if (mc->last_entry != NULL && + mc->last_entry->paddr_index == address_index && !lock && !size && test_bits(address_offset >> XC_PAGE_SHIFT, test_bit_size >> XC_PAGE_SHIFT, - mapcache->last_entry->valid_mapping)) { + mc->last_entry->valid_mapping)) { trace_xen_map_cache_return( - mapcache->last_entry->vaddr_base + address_offset + mc->last_entry->vaddr_base + address_offset ); - return mapcache->last_entry->vaddr_base + address_offset; + return mc->last_entry->vaddr_base + address_offset; } /* size is always a multiple of MCACHE_BUCKET_SIZE */ @@ -291,7 +292,7 @@ tryagain: cache_size = MCACHE_BUCKET_SIZE; } - entry = &mapcache->entry[address_index % mapcache->nr_buckets]; + entry = &mc->entry[address_index % mc->nr_buckets]; while (entry && (lock || entry->lock) && entry->vaddr_base && (entry->paddr_index != address_index || entry->size != cache_size || @@ -326,10 +327,10 @@ tryagain: if(!test_bits(address_offset >> XC_PAGE_SHIFT, test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { - mapcache->last_entry = NULL; + mc->last_entry = NULL; #ifdef XEN_COMPAT_PHYSMAP - if (!translated && mapcache->phys_offset_to_gaddr) { - phys_addr = mapcache->phys_offset_to_gaddr(phys_addr, size); + if (!translated && mc->phys_offset_to_gaddr) { + phys_addr = mc->phys_offset_to_gaddr(phys_addr, size); translated = true; goto tryagain; } @@ -342,7 +343,7 @@ tryagain: return NULL; } - mapcache->last_entry = entry; + mc->last_entry = entry; if (lock) { MapCacheRev *reventry = g_new0(MapCacheRev, 1); entry->lock++; @@ -352,16 +353,16 @@ tryagain: abort(); } reventry->dma = dma; - reventry->vaddr_req = mapcache->last_entry->vaddr_base + address_offset; - reventry->paddr_index = mapcache->last_entry->paddr_index; + reventry->vaddr_req = mc->last_entry->vaddr_base + address_offset; + reventry->paddr_index = mc->last_entry->paddr_index; reventry->size = entry->size; - QTAILQ_INSERT_HEAD(&mapcache->locked_entries, reventry, next); + QTAILQ_INSERT_HEAD(&mc->locked_entries, reventry, next); } trace_xen_map_cache_return( - mapcache->last_entry->vaddr_base + address_offset + mc->last_entry->vaddr_base + address_offset ); - return mapcache->last_entry->vaddr_base + address_offset; + return mc->last_entry->vaddr_base + address_offset; } uint8_t *xen_map_cache(hwaddr phys_addr, hwaddr size, @@ -370,7 +371,7 @@ uint8_t *xen_map_cache(hwaddr phys_addr, hwaddr size, uint8_t *p; mapcache_lock(mapcache); - p = xen_map_cache_unlocked(phys_addr, size, lock, dma); + p = xen_map_cache_unlocked(mapcache, phys_addr, size, lock, dma); mapcache_unlock(mapcache); return p; } From patchwork Tue Apr 30 16:49:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649666 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 12DB0C10F16 for ; Tue, 30 Apr 2024 16:51:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qhA-0000BA-Uq; Tue, 30 Apr 2024 12:51:10 -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 1s1qgX-0006K2-V6 for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:37 -0400 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgQ-00061u-5W for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:28 -0400 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-5196fe87775so6617984e87.3 for ; Tue, 30 Apr 2024 09:50:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495819; x=1715100619; 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=tHpYiWdb1lRh1fu1PHA0f9wMvB4Yb/LL+pZsTJlPtLc=; b=MOTLlKnPP2IEzdDDJu82cv7i1LDljQn2lzoqggOqoMupkMK5YyY3LdFJP/B+AsN2eC 4HqjxdcDYRSpldegV0l8Dt/8xY4d7awG7luGgmqKP+P+bn8VHY1CIdScVNiEdze3+Tt0 nk8UgYPdKI5o1KEq3gCwtqx3rxmdGwv5OS6yZOuUShr2undRu+W358Wb4N6ua3/oxex1 0JnhlbP2H6hRSFHxt3H3bWiMAP9NhMIs9OIn/WhX56IPJFryg/FyjS9cos3SkoF9M3d7 C4zuIroUS0xssSvP5K7h2aYuRoq1gDI52HyDa83Sn/6WXxKm8HMb9UEFnt760oDuMz+J FZtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495819; x=1715100619; 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=tHpYiWdb1lRh1fu1PHA0f9wMvB4Yb/LL+pZsTJlPtLc=; b=H5u6I3Y/VLICawpIKhkZbxrvDnmfVbOXFK1Ib7dLnV823he2XLHSf9DyrVUM63cQ7+ L2oU/Auej0IRz3We/73rlzYxsQMh2iwxWLipAq+m+VDdb/J9lrnft8IV2/hn+WAqQ1o5 YXPRrLQL1uXETNachy0Yk/euscsKzYJgf2NadCEt3Ttb2bB/sRG+E67Rq+aN15rhW5ux c/eo77Fs0ejbHYWemeimSjUMRVBwiZGFxYZOv6FutRu0j75h8bCK6j4SAd9h7OM+1t9w 4Pl6fTqbjOKTKKkMshe+op+GsZ0KcHI1gFHgLWLB6etLoc1Ywt42EdXOWfcU/BRrzvAY MyGQ== X-Gm-Message-State: AOJu0Yw0EbvmSsup9zuKrptZ2wvOdPNtOx3v1hulBYXZW47skKTmQP/y dmNAlun98FYrR20J0OpuXClq73blQG1nibDE2WYliKTIND2s0wX2YyRLrmwP X-Google-Smtp-Source: AGHT+IEpEAlJbJJD0/i+Lg344tcB9Tgltle5Mn6nu5CvyosHwr7HnsfYB92Ti4D7O/r40axqDFX0Iw== X-Received: by 2002:a05:6512:3981:b0:51b:f224:7025 with SMTP id j1-20020a056512398100b0051bf2247025mr20846lfu.59.1714495819141; Tue, 30 Apr 2024 09:50:19 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id y26-20020ac2421a000000b0051aada24366sm4312545lfh.66.2024.04.30.09.50.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:18 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony Perard , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v4 05/17] xen: mapcache: Refactor xen_remap_bucket for multi-instance Date: Tue, 30 Apr 2024 18:49:27 +0200 Message-Id: <20240430164939.925307-6-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12a; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x12a.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Edgar E. Iglesias" Add MapCache argument to xen_remap_bucket in preparation to support multiple map caches. No functional changes. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini Reviewed-by: Philippe Mathieu-Daudé --- hw/xen/xen-mapcache.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index 896021d86f..326a9b61ca 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -139,7 +139,8 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque) mapcache->entry = g_malloc0(size); } -static void xen_remap_bucket(MapCacheEntry *entry, +static void xen_remap_bucket(MapCache *mc, + MapCacheEntry *entry, void *vaddr, hwaddr size, hwaddr address_index, @@ -313,14 +314,14 @@ tryagain: if (!entry) { entry = g_new0(MapCacheEntry, 1); pentry->next = entry; - xen_remap_bucket(entry, NULL, cache_size, address_index, dummy); + xen_remap_bucket(mc, entry, NULL, cache_size, address_index, dummy); } else if (!entry->lock) { if (!entry->vaddr_base || entry->paddr_index != address_index || entry->size != cache_size || !test_bits(address_offset >> XC_PAGE_SHIFT, test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { - xen_remap_bucket(entry, NULL, cache_size, address_index, dummy); + xen_remap_bucket(mc, entry, NULL, cache_size, address_index, dummy); } } @@ -587,7 +588,7 @@ static uint8_t *xen_replace_cache_entry_unlocked(hwaddr old_phys_addr, trace_xen_replace_cache_entry_dummy(old_phys_addr, new_phys_addr); - xen_remap_bucket(entry, entry->vaddr_base, + xen_remap_bucket(mapcache, entry, entry->vaddr_base, cache_size, address_index, false); if (!test_bits(address_offset >> XC_PAGE_SHIFT, test_bit_size >> XC_PAGE_SHIFT, From patchwork Tue Apr 30 16:49:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649664 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C8E31C4345F for ; Tue, 30 Apr 2024 16:51:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qgs-0007j4-Mg; Tue, 30 Apr 2024 12:50:50 -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 1s1qgU-0006HS-3s for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:32 -0400 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgR-000622-Tg for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:25 -0400 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-51ab4ee9df8so7531140e87.1 for ; Tue, 30 Apr 2024 09:50:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495821; x=1715100621; 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=6Ebca77e5IYL9WEAaF2UYa4r/GkVpnh2Kl3ta9A5c+4=; b=msClK3kX2jHfgGigTJzGxYDXa1R4plXADb2JeN+CbN80faeQB1oKFtxSETJnQ0WNA5 PtB3WP79tlmzKVSCVswwPOrrgZWxnjFOVN+4SC9NBYyHks83c/50WOqwiDnyqkbmcDan 55Xo6IxRUYnja6B6JE1z1P1U5GS9cJ7MJnOd1A61J0fUOlB+BN5g/xLvPtK4804azvSw vKpA+nKN+4v9J8FFGSOx3laIPgdtrEpwFFWaVkafDh0dE5RCAOcsQSnmnWc49xg71Vra 4j6M1vTnzzv4piVyY6XvrK6L1ZnXogJm+7p1edZrOg4GMfBaQY5uXy3ebJTNsqAoFZAi Y2qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495821; x=1715100621; 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=6Ebca77e5IYL9WEAaF2UYa4r/GkVpnh2Kl3ta9A5c+4=; b=F2tnSIFWx8C/PIkHDK2k9RTinlJ2dY4NM8iFfMF6b5y+7woCxa4x8t2g3e/mNXB3QN 50Pb74M6gbvULEN9TTMxj8HKhtJ6fDhn+JUdxOxMpF6AjM/vfqgmb9UBITZTQh4UOK9W tCGTaA2HC0kk8GKl8v2HGNW7SvOX/T0kbe/d/f+IyVvLE3hDWxYMUyaL5sJ8hHCIoNNP lDSLDJQzb399JYvo2P85j8g80jviNNCKxrZHM2ncn+6LEfKVgsXlcbSk7iYpbF4UYWkD ebWzreMIzdN11OdQoemwSW6qmOFnLJkXhKYTfWXvg85lJT+/LCfJVJYa3Z3bu4gYYsfJ O+sw== X-Gm-Message-State: AOJu0Ywaqp/YAjUM/61rU4Xn5VwscyPw8mZMRT4kFm2S+R+mRFGNsYaf F38xwrqDyzRitHir7+bZIZ6+3Ext+wZz3wbSbVD7nQM4X81gQtBjPSGin+MK X-Google-Smtp-Source: AGHT+IEM3Jz9S/DKrWu5RICfZqu5IuAbuhDXbfyJpfQLWPTCw63HqZI9CE91kUAd3S8w9gG9YoAS8w== X-Received: by 2002:a05:6512:1386:b0:516:cc06:fa03 with SMTP id fc6-20020a056512138600b00516cc06fa03mr23704lfb.56.1714495821221; Tue, 30 Apr 2024 09:50:21 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id k3-20020a05651210c300b0051d7d7a21d7sm1000646lfg.308.2024.04.30.09.50.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:19 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony Perard , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v4 06/17] xen: mapcache: Break out xen_ram_addr_from_mapcache_single Date: Tue, 30 Apr 2024 18:49:28 +0200 Message-Id: <20240430164939.925307-7-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::135; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x135.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, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Edgar E. Iglesias" Break out xen_ram_addr_from_mapcache_single(), a multi-cache aware version of xen_ram_addr_from_mapcache. No functional changes. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini Reviewed-by: Philippe Mathieu-Daudé --- hw/xen/xen-mapcache.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index 326a9b61ca..d2deff70c8 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -377,7 +377,7 @@ uint8_t *xen_map_cache(hwaddr phys_addr, hwaddr size, return p; } -ram_addr_t xen_ram_addr_from_mapcache(void *ptr) +static ram_addr_t xen_ram_addr_from_mapcache_single(MapCache *mc, void *ptr) { MapCacheEntry *entry = NULL; MapCacheRev *reventry; @@ -386,8 +386,8 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr) ram_addr_t raddr; int found = 0; - mapcache_lock(mapcache); - QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) { + mapcache_lock(mc); + QTAILQ_FOREACH(reventry, &mc->locked_entries, next) { if (reventry->vaddr_req == ptr) { paddr_index = reventry->paddr_index; size = reventry->size; @@ -396,11 +396,11 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr) } } if (!found) { - mapcache_unlock(mapcache); + mapcache_unlock(mc); return RAM_ADDR_INVALID; } - entry = &mapcache->entry[paddr_index % mapcache->nr_buckets]; + entry = &mc->entry[paddr_index % mc->nr_buckets]; while (entry && (entry->paddr_index != paddr_index || entry->size != size)) { entry = entry->next; } @@ -411,10 +411,15 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr) raddr = (reventry->paddr_index << MCACHE_BUCKET_SHIFT) + ((unsigned long) ptr - (unsigned long) entry->vaddr_base); } - mapcache_unlock(mapcache); + mapcache_unlock(mc); return raddr; } +ram_addr_t xen_ram_addr_from_mapcache(void *ptr) +{ + return xen_ram_addr_from_mapcache_single(mapcache, ptr); +} + static void xen_invalidate_map_cache_entry_unlocked(uint8_t *buffer) { MapCacheEntry *entry = NULL, *pentry = NULL; From patchwork Tue Apr 30 16:49:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649672 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 591DEC10F16 for ; Tue, 30 Apr 2024 16:52:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qgl-0006iR-0P; Tue, 30 Apr 2024 12:50:43 -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 1s1qgX-0006K6-V8 for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:37 -0400 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgT-00062C-ST for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:28 -0400 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-516d1ecaf25so8212261e87.2 for ; Tue, 30 Apr 2024 09:50:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495823; x=1715100623; 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=1t+fSrRYl5L3yQvPVldSqnOrtZxoJXX623JAMweDjXA=; b=LX7u3B3KomLTQZZinVI25jA1zH0M9BBnffiPE+uUnsoe1JxtlVdkR2xzSZiqR8fSYy a0apJL3WGfp9X73ks4k8K/DZz1gpX7wzrYHD30P+BqM3LjLKMte9NagJmHvo+1enD4ND UMNlVxmRsv8rXDoFTJmg4yFk/DSihaszLIDiV/xIjN6vjHMBmSoRYSm2ucEp2Rl3F4ud eH2Y8t2oz8QQ7oUM+lwfO4ug0YT+HJwqo8S0eJXHqsUQD4OS4lGEZW2kvcyOOr7vR/it fxhrC8pVPxhFii/RHywMaWU5KJjkq2EcSs5Qydo9TV/ORke6/0DLRJdGKlRZIIybTul5 dZeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495823; x=1715100623; 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=1t+fSrRYl5L3yQvPVldSqnOrtZxoJXX623JAMweDjXA=; b=QhJBpySNzrDyilAwV4RxVbPw0+ggM5HmbT+zzJ9qdbEY+ZDDEUQT6bcgZ33jLXtUEQ UEoTlO98TbsafSlQz66ILjWT9YQ4nZOXVvoMRS6kvIdDiSuQXBVZbhAs6W7ByPD1tISx QterC+J8sn9GAzR0FSnETh5kOfcI2mUmJ7jWzfmibryw7xJ2XCAmQA37+ga6Nz+cd7a6 hMj/lJd6+/iDYdTvGxouMnWvEb8MUXmgbMpT9NmGt1n50q1lzWwbQLQ+iTjIYKIl06/p 8vkDTqaTOnJC2SW3HpSe8gflUWLNr8fzUcXFCga2+Hs5656QeseR8+0qgj3Cjgu0z5Wr INfA== X-Gm-Message-State: AOJu0YyAH5pxD/fWbCkF3A4ynrnKen1osZGoKBzOu0deySJWRShrI2uK OnvPD8HyTs1EbxV0TVgLBhymy0+P8fzxmRVCOBipHykoyEqgHONw4319j9N/ X-Google-Smtp-Source: AGHT+IH8tNB+OMEEjfoZnK00fenwXOTSLhumxvmYC1KCq8f4Ohl2Q8/E13IsvLGqDP3McXiamSkmOA== X-Received: by 2002:a05:6512:3d23:b0:51d:682d:c2ab with SMTP id d35-20020a0565123d2300b0051d682dc2abmr35470lfv.32.1714495822602; Tue, 30 Apr 2024 09:50:22 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id d18-20020ac24c92000000b0051bbba4541bsm2593600lfl.165.2024.04.30.09.50.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:21 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony Perard , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v4 07/17] xen: mapcache: Refactor xen_replace_cache_entry_unlocked Date: Tue, 30 Apr 2024 18:49:29 +0200 Message-Id: <20240430164939.925307-8-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12d; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x12d.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, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Edgar E. Iglesias" Add MapCache argument to xen_replace_cache_entry_unlocked in preparation for supporting multiple map caches. No functional change. Signed-off-by: Edgar E. Iglesias Reviewed-by: Philippe Mathieu-Daudé --- hw/xen/xen-mapcache.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index d2deff70c8..6e758eff94 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -556,7 +556,8 @@ void xen_invalidate_map_cache(void) mapcache_unlock(mapcache); } -static uint8_t *xen_replace_cache_entry_unlocked(hwaddr old_phys_addr, +static uint8_t *xen_replace_cache_entry_unlocked(MapCache *mc, + hwaddr old_phys_addr, hwaddr new_phys_addr, hwaddr size) { @@ -578,7 +579,7 @@ static uint8_t *xen_replace_cache_entry_unlocked(hwaddr old_phys_addr, cache_size += MCACHE_BUCKET_SIZE - (cache_size % MCACHE_BUCKET_SIZE); } - entry = &mapcache->entry[address_index % mapcache->nr_buckets]; + entry = &mc->entry[address_index % mc->nr_buckets]; while (entry && !(entry->paddr_index == address_index && entry->size == cache_size)) { entry = entry->next; @@ -614,7 +615,8 @@ uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr, uint8_t *p; mapcache_lock(mapcache); - p = xen_replace_cache_entry_unlocked(old_phys_addr, new_phys_addr, size); + p = xen_replace_cache_entry_unlocked(mapcache, old_phys_addr, + new_phys_addr, size); mapcache_unlock(mapcache); return p; } From patchwork Tue Apr 30 16:49:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D965CC25B10 for ; Tue, 30 Apr 2024 16:51:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qgq-0007Zq-Qx; Tue, 30 Apr 2024 12:50:50 -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 1s1qgZ-0006Ln-Rk for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:37 -0400 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgV-00062K-On for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:30 -0400 Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-51ac5923ef6so8251e87.0 for ; Tue, 30 Apr 2024 09:50:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495824; x=1715100624; 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=Fl7u/xU9kjPK32PHrP3OybWWMA4e16GqaL6Xbstmvbo=; b=ZSZjD51uNd8i7erT+VldYZ1iRtMoY+GZZCYThpn18CgJeRzTPC2Qehu/DEheflMQBd bAJMBdK2ojL6tCUqaBunHkuFSanFjjsN15K6UAWyMjz7ZUN0phYat/kIrJ5Flg2RSfDl AuKGoVUNGX6oOUrDJBvWvXEcDvdesK4ymmu+DFdJddEPur9Rtd8FY9YflXBrpAywR6rH 0Eixs6FPxoCDf/0T5BcP2AKUD7HJrkF8wPlA5RQidL1eb2z2KBXN/pA0m9KkTmQeUO0q Vd4Yj+kMH9rGPXDinzF1zyU3xyej/7jhEiIX8g3+agdUxtCTHdLyF4tvEgSmiaNp2LAc e65g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495824; x=1715100624; 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=Fl7u/xU9kjPK32PHrP3OybWWMA4e16GqaL6Xbstmvbo=; b=gmP0SZDVdJLfYYAZT3WHwp8vCrMf/Wae15LYnyI+6Z48sCmimVk4QBJ43DshLQM7ux C0fJ93DeBxYcz8vlzbI0JY4JUrqctzdpx9OVPQo2fTooBHCMbHaROyMxXef8wApo/KkV tBGpyjgr679HnvycBOPgNRDh+dA1Wci+tRIngBWtdAV+GbKrKw09WbOQKVU4NXs8Fo08 +46szHPP5JdTUWRs3gBmcm0piysvvAQwdrk1JVhXF+4MQxpLdN4QCBkvyULqcl49yILi 6xaL1nfS28EfmeKE8OU3+okzrrAo8ZctoeMfQnJtkjcpnBR4agn6reC1RaGrHogLML0h gJTA== X-Gm-Message-State: AOJu0Ywco0JCiSFqc5OM6YtO+k53MP6oz4YfYOiikTxTyV9j1AGOdbnL +7JYXRJ36r3LUScArXMF9NwwtHZmVZVnh1/b24kv4EEXE3Xs5dBZB91zzNKr X-Google-Smtp-Source: AGHT+IEr1VKCghuiim9RyIssq8iqWzgedXC6VPdssb/073WGO5FTX1lD3Adw0P8JM08/qNMg1AdtBQ== X-Received: by 2002:ac2:5f01:0:b0:51d:6630:b83f with SMTP id 1-20020ac25f01000000b0051d6630b83fmr89702lfq.17.1714495824584; Tue, 30 Apr 2024 09:50:24 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id h18-20020a197012000000b0051d9149a2cesm917564lfc.84.2024.04.30.09.50.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:23 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony Perard , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v4 08/17] xen: mapcache: Refactor xen_invalidate_map_cache_entry_unlocked Date: Tue, 30 Apr 2024 18:49:30 +0200 Message-Id: <20240430164939.925307-9-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12e; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x12e.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, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Edgar E. Iglesias" Add MapCache argument to xen_invalidate_map_cache_entry_unlocked. This is in preparation for supporting multiple map caches. No functional changes. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini Reviewed-by: Philippe Mathieu-Daudé --- hw/xen/xen-mapcache.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index 6e758eff94..34454da2f6 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -420,7 +420,8 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr) return xen_ram_addr_from_mapcache_single(mapcache, ptr); } -static void xen_invalidate_map_cache_entry_unlocked(uint8_t *buffer) +static void xen_invalidate_map_cache_entry_unlocked(MapCache *mc, + uint8_t *buffer) { MapCacheEntry *entry = NULL, *pentry = NULL; MapCacheRev *reventry; @@ -428,7 +429,7 @@ static void xen_invalidate_map_cache_entry_unlocked(uint8_t *buffer) hwaddr size; int found = 0; - QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) { + QTAILQ_FOREACH(reventry, &mc->locked_entries, next) { if (reventry->vaddr_req == buffer) { paddr_index = reventry->paddr_index; size = reventry->size; @@ -438,7 +439,7 @@ static void xen_invalidate_map_cache_entry_unlocked(uint8_t *buffer) } if (!found) { trace_xen_invalidate_map_cache_entry_unlocked_not_found(buffer); - QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) { + QTAILQ_FOREACH(reventry, &mc->locked_entries, next) { trace_xen_invalidate_map_cache_entry_unlocked_found( reventry->paddr_index, reventry->vaddr_req @@ -446,15 +447,15 @@ static void xen_invalidate_map_cache_entry_unlocked(uint8_t *buffer) } return; } - QTAILQ_REMOVE(&mapcache->locked_entries, reventry, next); + QTAILQ_REMOVE(&mc->locked_entries, reventry, next); g_free(reventry); - if (mapcache->last_entry != NULL && - mapcache->last_entry->paddr_index == paddr_index) { - mapcache->last_entry = NULL; + if (mc->last_entry != NULL && + mc->last_entry->paddr_index == paddr_index) { + mc->last_entry = NULL; } - entry = &mapcache->entry[paddr_index % mapcache->nr_buckets]; + entry = &mc->entry[paddr_index % mc->nr_buckets]; while (entry && (entry->paddr_index != paddr_index || entry->size != size)) { pentry = entry; entry = entry->next; @@ -488,7 +489,7 @@ static void xen_invalidate_map_cache_entry_bh(void *opaque) XenMapCacheData *data = opaque; mapcache_lock(mapcache); - xen_invalidate_map_cache_entry_unlocked(data->buffer); + xen_invalidate_map_cache_entry_unlocked(mapcache, data->buffer); mapcache_unlock(mapcache); aio_co_wake(data->co); @@ -506,7 +507,7 @@ void coroutine_mixed_fn xen_invalidate_map_cache_entry(uint8_t *buffer) qemu_coroutine_yield(); } else { mapcache_lock(mapcache); - xen_invalidate_map_cache_entry_unlocked(buffer); + xen_invalidate_map_cache_entry_unlocked(mapcache, buffer); mapcache_unlock(mapcache); } } From patchwork Tue Apr 30 16:49:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 73AA2C4345F for ; Tue, 30 Apr 2024 16:51:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qgq-0007fs-N0; Tue, 30 Apr 2024 12:50:48 -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 1s1qgd-0006R2-D5 for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:37 -0400 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgX-00062T-Lx for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:32 -0400 Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-516d2600569so7363413e87.0 for ; Tue, 30 Apr 2024 09:50:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495826; x=1715100626; 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=kom/SHDfVUZpmIZv8oD+sehGVIlmksQJn6703to5aOw=; b=BKzV8L/ZbU8k0t+UCnLCHRhG/69tFqUuWWD9nWrcz6Kvx+DZRVoqB85ADB6oc57ONL aKzxzZiChLptuN4fAnddeXaLkJpH7ia/0FGFdIVyvF7OKIEMlqWyV2FnxA+2Hxxl5ce0 BqJd/rlLQVM1L9uGILDM3e8Rs2vZKXyFPBTdkv1bfQJNMECVWGlxaXe8FnJXgIYt/IfJ /CjLfYvwteuuAflfTcOyVlOPYWq586HYlXKBnCWNGuP53R0pmBabfJ38vflmUf1fa3MR k7NwO91fzUqIxlXuqTyUh6c8vPnr/yBZXC0NjCnd4eISudntD0Qy1k4QRTifk+KsT7bW 6kfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495826; x=1715100626; 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=kom/SHDfVUZpmIZv8oD+sehGVIlmksQJn6703to5aOw=; b=kRk2hfDXkUnLkytzDsGg5t5qzHVJP/M9QZl4fRDgBYbZNjWnyy0SR/Dv9UjxBeUswC bjaCcPbdDgScbBb6ZgJUoh04fen4x2QJts4lYzvexKhHMk1Om/O/g8mU5+qGvPRs7cxS 0D6PdIhOrpk1gM3fSEkOVBzDzaNAf5Pf6R95k/XJRY10MtXqdHaZnZExsGYVwM48tris x24b9yMSqgx58v9unv4gJJ//YunfeKADGfN1OXHbYatW5/7fh9bXiGQlHEkYniptIXvX vPxXJcRZyxfOJgS8mIggjK2mm+8pgrDQT1ZqxxKXEwH0EkRV3N2TS1hu+jLGNx+kZhz9 CdAg== X-Gm-Message-State: AOJu0Yz5LejvGApVHYhA2atHSf39UMFeEeY1llwzpGHCxTB/5oNx/kZk OcUwfiE+0kgerBkzWkkiv/hTM1GSHUiQmMCDJwHGVhfHKPu68dW6Xc1ZN8rU X-Google-Smtp-Source: AGHT+IFL7xixQZzyY4IgwLtRiYEyYk+uUHOVAzj9b5xqr6eOpzsgiDsvBW99qrlkBchrQCMFWP2fRg== X-Received: by 2002:ac2:5a50:0:b0:51c:f898:60cb with SMTP id r16-20020ac25a50000000b0051cf89860cbmr15984lfn.35.1714495826099; Tue, 30 Apr 2024 09:50:26 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id y24-20020a197518000000b00518b91e8fd7sm4495626lfe.235.2024.04.30.09.50.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:25 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony Perard , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v4 09/17] xen: mapcache: Break out xen_invalidate_map_cache_single() Date: Tue, 30 Apr 2024 18:49:31 +0200 Message-Id: <20240430164939.925307-10-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::132; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x132.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, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Edgar E. Iglesias" Break out xen_invalidate_map_cache_single(). No functional changes. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini Reviewed-by: Philippe Mathieu-Daudé --- hw/xen/xen-mapcache.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index 34454da2f6..dd08cd296b 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -512,17 +512,14 @@ void coroutine_mixed_fn xen_invalidate_map_cache_entry(uint8_t *buffer) } } -void xen_invalidate_map_cache(void) +static void xen_invalidate_map_cache_single(MapCache *mc) { unsigned long i; MapCacheRev *reventry; - /* Flush pending AIO before destroying the mapcache */ - bdrv_drain_all(); - - mapcache_lock(mapcache); + mapcache_lock(mc); - QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) { + QTAILQ_FOREACH(reventry, &mc->locked_entries, next) { if (!reventry->dma) { continue; } @@ -530,8 +527,8 @@ void xen_invalidate_map_cache(void) reventry->vaddr_req); } - for (i = 0; i < mapcache->nr_buckets; i++) { - MapCacheEntry *entry = &mapcache->entry[i]; + for (i = 0; i < mc->nr_buckets; i++) { + MapCacheEntry *entry = &mc->entry[i]; if (entry->vaddr_base == NULL) { continue; @@ -552,9 +549,17 @@ void xen_invalidate_map_cache(void) entry->valid_mapping = NULL; } - mapcache->last_entry = NULL; + mc->last_entry = NULL; - mapcache_unlock(mapcache); + mapcache_unlock(mc); +} + +void xen_invalidate_map_cache(void) +{ + /* Flush pending AIO before destroying the mapcache */ + bdrv_drain_all(); + + xen_invalidate_map_cache_single(mapcache); } static uint8_t *xen_replace_cache_entry_unlocked(MapCache *mc, From patchwork Tue Apr 30 16:49:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649684 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0F0DDC4345F for ; Tue, 30 Apr 2024 16:53:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qgo-0007Jw-Gv; Tue, 30 Apr 2024 12:50:46 -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 1s1qgc-0006Qv-Ne for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:37 -0400 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgY-00062m-BI for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:32 -0400 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-51c077cfc09so7022071e87.2 for ; Tue, 30 Apr 2024 09:50:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495828; x=1715100628; 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=j0mqQo2QzUWZGYHpYGMWslGBm8Oap0E4Z0qNuGo27BE=; b=R4R+riu6gcSBuWO7Dgjrh6Vb2Z3Meec/GS/vh+1BU+MFkVAj1QdHMMtXwCp75S/sLm IeHNnvQsXjLams01u8PzlLZ+IRG7xDLAxf0dY8dP7tejgjh33QDqhajsWUH1qGz8NEGK pagSsgruDDJwYYb+bU/xsBQ/X1FXmAu8BoYXytd1MnpIx4JKXna5Ycou4uZmu03zG5X0 /h3D5kzI6q+c9ILpgWXtlYwnbSTZhXyOSSXHBhPi+/1jIoOad7+hP4X7H6MtdwkE4upm vqCL+edBpUl26LdXwn6os5SaUN/IzPgyuQY168h4ZESqioYBF9YVw/45Mmbf8d4BpLSH Brpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495828; x=1715100628; 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=j0mqQo2QzUWZGYHpYGMWslGBm8Oap0E4Z0qNuGo27BE=; b=jnLWEomAqyvXzsfbW7fdUf7Pncm5Xi65TZqNbi1PrJm2F8GCbvjClsAJJWj4qidkgu 2Wgl7Gvvekbj/T7II0dnzUdpjsCyvL/lYs+o4emOoZ3FYTYUgWFEZJRDhVXrswKOe+T8 AeOpKsAlxDvlGh38wOwg63UZDuxay38OgCuTLr8Dj8SWCZ2V0UflPbzjDZWNhJyLBOU6 4Gz+PNGmprmIpAcETof4MbLeE2RZyPSrSddUW5+7kz1adUWwIEIIGBEOOlozolczAwCL kh1hGBsB2D71V9xyMsJSm8JRnoQVJA8d9lcO4D/kd7jCjsiMSzYzjvpkB+pitTWWyeYg v4Sw== X-Gm-Message-State: AOJu0YznPcJzi/qJ3yIFFPuyUomw5vyWCsJmv/w0Rt82QefRsVspW2zV /Mcx3w43IKTLpC1Nf+vrMe0lB4/hQwG0yiJbMQdwQQBCVIZTHvBGQrGx1pnl X-Google-Smtp-Source: AGHT+IGQCPL9JgHmD1RLCqV4syaus5YjfpEwlBgT76+qyDY37l2dNAYgiSCfXBlfwOjb2G8RuoFmJQ== X-Received: by 2002:ac2:4c4e:0:b0:51d:1830:8380 with SMTP id o14-20020ac24c4e000000b0051d18308380mr58334lfk.8.1714495827628; Tue, 30 Apr 2024 09:50:27 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id u17-20020a196a11000000b0051aaffe4f1dsm4252114lfu.79.2024.04.30.09.50.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:26 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony Perard , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v4 10/17] xen: mapcache: Break out xen_map_cache_init_single() Date: Tue, 30 Apr 2024 18:49:32 +0200 Message-Id: <20240430164939.925307-11-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12f; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x12f.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, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Edgar E. Iglesias" Break out xen_map_cache_init_single() in preparation for adding multiple map caches. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini --- hw/xen/xen-mapcache.c | 53 ++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index dd08cd296b..72a7e25e3e 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -93,23 +93,44 @@ static inline int test_bits(int nr, int size, const unsigned long *addr) return 0; } -void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque) +static MapCache *xen_map_cache_init_single(phys_offset_to_gaddr_t f, + void *opaque, + unsigned long max_size) { unsigned long size; - struct rlimit rlimit_as; + MapCache *mc; + + mc = g_new0(MapCache, 1); + + mc->phys_offset_to_gaddr = f; + mc->opaque = opaque; + qemu_mutex_init(&mc->lock); + + QTAILQ_INIT(&mc->locked_entries); - mapcache = g_new0(MapCache, 1); + mc->max_mcache_size = max_size; - mapcache->phys_offset_to_gaddr = f; - mapcache->opaque = opaque; - qemu_mutex_init(&mapcache->lock); + mc->nr_buckets = + (((mc->max_mcache_size >> XC_PAGE_SHIFT) + + (1UL << (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT)) - 1) >> + (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT)); - QTAILQ_INIT(&mapcache->locked_entries); + size = mc->nr_buckets * sizeof(MapCacheEntry); + size = (size + XC_PAGE_SIZE - 1) & ~(XC_PAGE_SIZE - 1); + trace_xen_map_cache_init(mc->nr_buckets, size); + mc->entry = g_malloc0(size); + return mc; +} + +void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque) +{ + struct rlimit rlimit_as; + unsigned long max_mcache_size; if (geteuid() == 0) { rlimit_as.rlim_cur = RLIM_INFINITY; rlimit_as.rlim_max = RLIM_INFINITY; - mapcache->max_mcache_size = MCACHE_MAX_SIZE; + max_mcache_size = MCACHE_MAX_SIZE; } else { getrlimit(RLIMIT_AS, &rlimit_as); rlimit_as.rlim_cur = rlimit_as.rlim_max; @@ -119,24 +140,14 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque) " memory is not infinity"); } if (rlimit_as.rlim_max < MCACHE_MAX_SIZE + NON_MCACHE_MEMORY_SIZE) { - mapcache->max_mcache_size = rlimit_as.rlim_max - - NON_MCACHE_MEMORY_SIZE; + max_mcache_size = rlimit_as.rlim_max - NON_MCACHE_MEMORY_SIZE; } else { - mapcache->max_mcache_size = MCACHE_MAX_SIZE; + max_mcache_size = MCACHE_MAX_SIZE; } } + mapcache = xen_map_cache_init_single(f, opaque, max_mcache_size); setrlimit(RLIMIT_AS, &rlimit_as); - - mapcache->nr_buckets = - (((mapcache->max_mcache_size >> XC_PAGE_SHIFT) + - (1UL << (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT)) - 1) >> - (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT)); - - size = mapcache->nr_buckets * sizeof (MapCacheEntry); - size = (size + XC_PAGE_SIZE - 1) & ~(XC_PAGE_SIZE - 1); - trace_xen_map_cache_init(mapcache->nr_buckets, size); - mapcache->entry = g_malloc0(size); } static void xen_remap_bucket(MapCache *mc, From patchwork Tue Apr 30 16:49:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649674 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 330C4C4345F for ; Tue, 30 Apr 2024 16:52:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qhJ-0000mo-3U; Tue, 30 Apr 2024 12:51:17 -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 1s1qgf-0006Tm-HS for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:39 -0400 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgZ-00063t-Oh for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:35 -0400 Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-51abf1a9332so8147592e87.3 for ; Tue, 30 Apr 2024 09:50:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495829; x=1715100629; 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=yOBKxxu7GyLSVYEkd97aCGdSreO6dnD3GZWBKg4jO3k=; b=kyqRgbDcGHfzSSPPytWeWi8QakY0NqOwDDfp8Vpy8r4gA767FMPmMeeBtaak9IVS8S GuRhCnsv2Gq5QB/X5C1LxYjkmMkoo+vH05/4H8kkUR2Oz1L29iSCtyQVAh9RFSsJR4Aa uqSP+5dT0ttoAQRLwNW/jA1ynLCBTE++JHFbNCwSrc7N7hItu2RhW2qa8dwYwpYTgp8n h6T0YUj6P11VcPlqpHcPIDikQBO69LP03XdlfJEq3012HbJqFEa1VTjrOofp62u+AfUQ lwKOTPj/ImjY+dwUgTEP5Je7oFraeGNrmNxiNs5zVLCDub7Xkjd4ke4kuphZnEluuHfE rTlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495829; x=1715100629; 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=yOBKxxu7GyLSVYEkd97aCGdSreO6dnD3GZWBKg4jO3k=; b=mYZnK3X96TbyNmTG4IAOOIKM3Z3hs8I22TSSlY3N1ZuHLk9jB2TjCYPRSXKWBTzQtC 6zuNKb6AK8041XU7z7l4JZjSkPrsDCl4nBSc+x0Wk+EIQJUHg9IgdOOlcKS3cLscaY6T PPNeH1t34BzLW2bm/oSTcDisVM437lSXA902+5bIn0DcPNz51jMrlSa62qqk2KIBW3SK M2dnnMSnydn6WBUcJTa3WLwUSuim4TQfYIwuAtasrbcFKgz4wDM0mPTgLKb8RhmvHYE/ rMNcCP7PAOh/BSCrbQMmDaEA+pRk99PENNB+B26jq4c2W+iTFO2h/xwSgiRXF+sAyWtg 9qfQ== X-Gm-Message-State: AOJu0YyMAlh/Kw3n+xy/Cq3oS403zKeisCHHshqZQxfdU7kYqDWnughz dbfBj1TV5okTlSKjIBogIdHcxk6pH4VBHvqOBE/9qWYMmOsz9HaWBG2ePLIt X-Google-Smtp-Source: AGHT+IG1D0QzmbnS0ErFMJ7lJMDglr0F3Y/2LZElzamvzuLYF8jqyCZc9cG7FMYyaCBToshoVVfqkw== X-Received: by 2002:ac2:5327:0:b0:513:1a9c:ae77 with SMTP id f7-20020ac25327000000b005131a9cae77mr26233lfh.52.1714495829133; Tue, 30 Apr 2024 09:50:29 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id b1-20020ac25621000000b00518b294570asm4561021lff.135.2024.04.30.09.50.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:28 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony Perard , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v4 11/17] xen: mapcache: Make MCACHE_BUCKET_SHIFT runtime configurable Date: Tue, 30 Apr 2024 18:49:33 +0200 Message-Id: <20240430164939.925307-12-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::132; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x132.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, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Edgar E. Iglesias" Make MCACHE_BUCKET_SHIFT runtime configurable per cache instance. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini --- hw/xen/xen-mapcache.c | 52 ++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index 72a7e25e3e..4f98d284dd 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -23,13 +23,10 @@ #if HOST_LONG_BITS == 32 -# define MCACHE_BUCKET_SHIFT 16 # define MCACHE_MAX_SIZE (1UL<<31) /* 2GB Cap */ #else -# define MCACHE_BUCKET_SHIFT 20 # define MCACHE_MAX_SIZE (1UL<<35) /* 32GB Cap */ #endif -#define MCACHE_BUCKET_SIZE (1UL << MCACHE_BUCKET_SHIFT) /* This is the size of the virtual address space reserve to QEMU that will not * be use by MapCache. @@ -65,7 +62,8 @@ typedef struct MapCache { /* For most cases (>99.9%), the page address is the same. */ MapCacheEntry *last_entry; unsigned long max_mcache_size; - unsigned int mcache_bucket_shift; + unsigned int bucket_shift; + unsigned long bucket_size; phys_offset_to_gaddr_t phys_offset_to_gaddr; QemuMutex lock; @@ -95,6 +93,7 @@ static inline int test_bits(int nr, int size, const unsigned long *addr) static MapCache *xen_map_cache_init_single(phys_offset_to_gaddr_t f, void *opaque, + unsigned int bucket_shift, unsigned long max_size) { unsigned long size; @@ -108,12 +107,14 @@ static MapCache *xen_map_cache_init_single(phys_offset_to_gaddr_t f, QTAILQ_INIT(&mc->locked_entries); + mc->bucket_shift = bucket_shift; + mc->bucket_size = 1UL << bucket_shift; mc->max_mcache_size = max_size; mc->nr_buckets = (((mc->max_mcache_size >> XC_PAGE_SHIFT) + - (1UL << (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT)) - 1) >> - (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT)); + (1UL << (bucket_shift - XC_PAGE_SHIFT)) - 1) >> + (bucket_shift - XC_PAGE_SHIFT)); size = mc->nr_buckets * sizeof(MapCacheEntry); size = (size + XC_PAGE_SIZE - 1) & ~(XC_PAGE_SIZE - 1); @@ -126,6 +127,13 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque) { struct rlimit rlimit_as; unsigned long max_mcache_size; + unsigned int bucket_shift; + + if (HOST_LONG_BITS == 32) { + bucket_shift = 16; + } else { + bucket_shift = 20; + } if (geteuid() == 0) { rlimit_as.rlim_cur = RLIM_INFINITY; @@ -146,7 +154,9 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque) } } - mapcache = xen_map_cache_init_single(f, opaque, max_mcache_size); + mapcache = xen_map_cache_init_single(f, opaque, + bucket_shift, + max_mcache_size); setrlimit(RLIMIT_AS, &rlimit_as); } @@ -195,7 +205,7 @@ static void xen_remap_bucket(MapCache *mc, entry->valid_mapping = NULL; for (i = 0; i < nb_pfn; i++) { - pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT)) + i; + pfns[i] = (address_index << (mc->bucket_shift - XC_PAGE_SHIFT)) + i; } /* @@ -266,8 +276,8 @@ static uint8_t *xen_map_cache_unlocked(MapCache *mc, bool dummy = false; tryagain: - address_index = phys_addr >> MCACHE_BUCKET_SHIFT; - address_offset = phys_addr & (MCACHE_BUCKET_SIZE - 1); + address_index = phys_addr >> mc->bucket_shift; + address_offset = phys_addr & (mc->bucket_size - 1); trace_xen_map_cache(phys_addr); @@ -294,14 +304,14 @@ tryagain: return mc->last_entry->vaddr_base + address_offset; } - /* size is always a multiple of MCACHE_BUCKET_SIZE */ + /* size is always a multiple of mc->bucket_size */ if (size) { cache_size = size + address_offset; - if (cache_size % MCACHE_BUCKET_SIZE) { - cache_size += MCACHE_BUCKET_SIZE - (cache_size % MCACHE_BUCKET_SIZE); + if (cache_size % mc->bucket_size) { + cache_size += mc->bucket_size - (cache_size % mc->bucket_size); } } else { - cache_size = MCACHE_BUCKET_SIZE; + cache_size = mc->bucket_size; } entry = &mc->entry[address_index % mc->nr_buckets]; @@ -419,7 +429,7 @@ static ram_addr_t xen_ram_addr_from_mapcache_single(MapCache *mc, void *ptr) trace_xen_ram_addr_from_mapcache_not_in_cache(ptr); raddr = RAM_ADDR_INVALID; } else { - raddr = (reventry->paddr_index << MCACHE_BUCKET_SHIFT) + + raddr = (reventry->paddr_index << mc->bucket_shift) + ((unsigned long) ptr - (unsigned long) entry->vaddr_base); } mapcache_unlock(mc); @@ -582,8 +592,8 @@ static uint8_t *xen_replace_cache_entry_unlocked(MapCache *mc, hwaddr address_index, address_offset; hwaddr test_bit_size, cache_size = size; - address_index = old_phys_addr >> MCACHE_BUCKET_SHIFT; - address_offset = old_phys_addr & (MCACHE_BUCKET_SIZE - 1); + address_index = old_phys_addr >> mc->bucket_shift; + address_offset = old_phys_addr & (mc->bucket_size - 1); assert(size); /* test_bit_size is always a multiple of XC_PAGE_SIZE */ @@ -592,8 +602,8 @@ static uint8_t *xen_replace_cache_entry_unlocked(MapCache *mc, test_bit_size += XC_PAGE_SIZE - (test_bit_size % XC_PAGE_SIZE); } cache_size = size + address_offset; - if (cache_size % MCACHE_BUCKET_SIZE) { - cache_size += MCACHE_BUCKET_SIZE - (cache_size % MCACHE_BUCKET_SIZE); + if (cache_size % mc->bucket_size) { + cache_size += mc->bucket_size - (cache_size % mc->bucket_size); } entry = &mc->entry[address_index % mc->nr_buckets]; @@ -606,8 +616,8 @@ static uint8_t *xen_replace_cache_entry_unlocked(MapCache *mc, return NULL; } - address_index = new_phys_addr >> MCACHE_BUCKET_SHIFT; - address_offset = new_phys_addr & (MCACHE_BUCKET_SIZE - 1); + address_index = new_phys_addr >> mc->bucket_shift; + address_offset = new_phys_addr & (mc->bucket_size - 1); trace_xen_replace_cache_entry_dummy(old_phys_addr, new_phys_addr); From patchwork Tue Apr 30 16:49:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649685 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E9E92C4345F for ; Tue, 30 Apr 2024 16:53:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qgo-0007HW-CE; Tue, 30 Apr 2024 12:50:46 -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 1s1qgi-0006Zy-KW for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:41 -0400 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgf-00064t-6E for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:40 -0400 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2de2f5ca076so67933021fa.0 for ; Tue, 30 Apr 2024 09:50:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495831; x=1715100631; 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=yU40+YVWxkJADy+Z4l2CwzlxvDSuLGvZgzgju3wrOiw=; b=Rbu1zNCaQsUcFY+ry1YphfcA+1qLkxp/QcIOcEBLJbgyVQN21mTFE1m4jSuRrtO4as krRX/zwRamD+EKQP8OE9w9A7A02f0OuKvtKZ3IYjpFN5oiRLLptILiKTcCUqGWYoqyIh rB6lpqB3F7/gogmnlh054SVms3w2G7tPIcS/Rq5At5ur052D5oMvjKlERSK79DzRBFIK sN/0dP4D5lp82GniqGy9ML65o0E77PpqzDOMYOOLgPGSsSeKKdltaVMBCyyOmDQ0NYmg SZVDlb/zkm8/zNINrpl8Bfd3PQOjLYzWqVyDgL9Rob4AXhSeZATfSaX/JPMu9ZC32i3f RpCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495831; x=1715100631; 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=yU40+YVWxkJADy+Z4l2CwzlxvDSuLGvZgzgju3wrOiw=; b=pzHRrxDSGT/lVi8W+haJh3cqYUiNv3metZNxgoCawwJenSn3RWu8EZPxAIjfzRDS0G s9Nry7yxdzBxVo/r/+QABpBytHLxix5RTmzlQoHB1laAZevhK4YdG+S3VTZY+G0WCo7J 0qXTJqFVXTaKtyp4TsWMn8i2dKuvCCr8hzG6ZJwCi0Rt6D9sbwP5+c19Xs/ZVsD5ENxU yY/uwKR+TpmMS979x9MikTaOtqAhpZfP7tpRZiwDxJnyo+zEcJgyXo2XJf3p+/ajhBgF o0VkiB4yJPmH9129ZOtKvXbTw0gzaoqNcIz3dudTsr6sNN1cpQUsR8GtZqLFKF9Jtc7h KcyQ== X-Gm-Message-State: AOJu0YyLYhcrqjEwwkPrhKnPZ9KolK5/PRlL60tau4R97o/lX2wa84xO 5C6PRbDpNWBX6t9R1qMzO1W9D+x9rVm1AtYckkdW6cb1/eD6ayIBWXxOCJDL X-Google-Smtp-Source: AGHT+IF7NEHMVH11qhcbPGrROL4h9vPrTZ7L+HcLgKWakMJjuqsmWO3glx5CsV2GXCvTV6HEwqtzvg== X-Received: by 2002:ac2:4984:0:b0:51c:c1a3:a4f9 with SMTP id f4-20020ac24984000000b0051cc1a3a4f9mr13762lfl.64.1714495831228; Tue, 30 Apr 2024 09:50:31 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id f13-20020a056512360d00b0051ad4552454sm3943178lfs.148.2024.04.30.09.50.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:30 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony Perard , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v4 12/17] xen: mapcache: Unmap first entries in buckets Date: Tue, 30 Apr 2024 18:49:34 +0200 Message-Id: <20240430164939.925307-13-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::232; envelope-from=edgar.iglesias@gmail.com; helo=mail-lj1-x232.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, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Edgar E. Iglesias" When invalidating memory ranges, if we happen to hit the first entry in a bucket we were never unmapping it. This was harmless for foreign mappings but now that we're looking to reuse the mapcache for transient grant mappings, we must unmap entries when invalidated. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini --- hw/xen/xen-mapcache.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index 4f98d284dd..0365311788 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -486,18 +486,22 @@ static void xen_invalidate_map_cache_entry_unlocked(MapCache *mc, return; } entry->lock--; - if (entry->lock > 0 || pentry == NULL) { + if (entry->lock > 0) { return; } - pentry->next = entry->next; ram_block_notify_remove(entry->vaddr_base, entry->size, entry->size); if (munmap(entry->vaddr_base, entry->size) != 0) { perror("unmap fails"); exit(-1); } - g_free(entry->valid_mapping); - g_free(entry); + if (pentry) { + pentry->next = entry->next; + g_free(entry->valid_mapping); + g_free(entry); + } else { + memset(entry, 0, sizeof *entry); + } } typedef struct XenMapCacheData { From patchwork Tue Apr 30 16:49:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649678 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 44F57C25B5C for ; Tue, 30 Apr 2024 16:52:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qhH-0000cP-W5; Tue, 30 Apr 2024 12:51:16 -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 1s1qgk-0006nr-9Z for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:43 -0400 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgh-00065B-5L for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:41 -0400 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-51ca95db667so5702737e87.0 for ; Tue, 30 Apr 2024 09:50:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495833; x=1715100633; 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=DU0xtzI9Cm5N5WksUYgPVqXR4B2xCZmxh2qO529TbRk=; b=ZQNnnBvdj4R9M70zfuHqHMAalF+cPBVom1jP4zTWFeOLkJa2iJunutXx4BY3Fq7YeT mp1ZFirYZT6pRS9wnm1sUpLpIDkEGihTrVW+pP5TEmcQBm880LFzp7OKVgc5Oz1uQHWZ s6ax08qfczEwdfEwxJFiy23pk+9fWcyNG5uroM15A74mvhUt37ruLtvp6SpB7sYjmXU1 4H+Ye2QFdyoyze3Farobia4+DliWEhFm2HKr43opJFl1fp7kdnjddClJh+RVmuhdKvlj 6UnjWolWNJwIdKl9k71L+Fdk9SI4DQFSvrLVELl/tC90gUP6mo6+lXR6tpJ+jnzAvKSl 5pLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495833; x=1715100633; 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=DU0xtzI9Cm5N5WksUYgPVqXR4B2xCZmxh2qO529TbRk=; b=gRUVDRAZnzxSfNYg4DIEJAk8x2hityuWBH/eBpQUZGDi3UvNGZgQ0VdC4FoytCIRGv EqbIT3ctMr+LXf0iCYMiUS1iDlMIasHWqfKlqbm2tuiXksQXYtp6MnNi5vRK0Soo9kWB FCEFDnpBUgVaFunkspG+jdsCXZiaChYUlrtOlFTq7x8u+nD9SDA3IsWKGCz0wHMyQH5t s3S54MoXi6e5Fxd8Hiv6E4bZoM0ApzVwH0MBszdGg7vdDxXH6r/2RPqTZpGPqAUa2y+F nr2cyUeLparI341XOmmyMZpWVneANj76+NWt6HdRQPilt7tDlEF7d2jUpqeyUJ06ExCk sbRw== X-Gm-Message-State: AOJu0YxqbSNx++RB2aqdG0fFeGtVdnrdUnYOUIaYTDpuRvXn2LjgluNH 4xekQ/bIbKyp9z9gy8f873sIRzTSXUbCyHkStihbU5Wm3iLPOEtTiUZqVlqw X-Google-Smtp-Source: AGHT+IH5mCn6s8y3JJfLC094G9xqUv22UPPMyi0CQHk4jd06RZgbi6+GzYUXShvTx3wLunuX1iTX8w== X-Received: by 2002:ac2:4852:0:b0:515:a8c9:6e99 with SMTP id 18-20020ac24852000000b00515a8c96e99mr42447lfy.5.1714495833071; Tue, 30 Apr 2024 09:50:33 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id f15-20020a19380f000000b0051aaf26f4a0sm4359741lfa.101.2024.04.30.09.50.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:32 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony Perard , Paul Durrant , Paolo Bonzini , Peter Xu , David Hildenbrand , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , xen-devel@lists.xenproject.org Subject: [PATCH v4 13/17] softmmu: Pass RAM MemoryRegion and is_write xen_map_cache() Date: Tue, 30 Apr 2024 18:49:35 +0200 Message-Id: <20240430164939.925307-14-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::133; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x133.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, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Edgar E. Iglesias" Propagate MR and is_write to xen_map_cache(). This is in preparation for adding support for grant mappings. No functional change. Signed-off-by: Edgar E. Iglesias Acked-by: Peter Xu Reviewed-by: Stefano Stabellini Reviewed-by: David Hildenbrand Reviewed-by: Philippe Mathieu-Daudé --- hw/xen/xen-mapcache.c | 10 ++++++---- include/sysemu/xen-mapcache.h | 11 +++++++---- system/physmem.c | 31 +++++++++++++++++++++++-------- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index 0365311788..09b5f36d9c 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -264,7 +264,7 @@ static void xen_remap_bucket(MapCache *mc, static uint8_t *xen_map_cache_unlocked(MapCache *mc, hwaddr phys_addr, hwaddr size, - uint8_t lock, bool dma) + uint8_t lock, bool dma, bool is_write) { MapCacheEntry *entry, *pentry = NULL, *free_entry = NULL, *free_pentry = NULL; @@ -387,13 +387,15 @@ tryagain: return mc->last_entry->vaddr_base + address_offset; } -uint8_t *xen_map_cache(hwaddr phys_addr, hwaddr size, - uint8_t lock, bool dma) +uint8_t *xen_map_cache(MemoryRegion *mr, + hwaddr phys_addr, hwaddr size, + uint8_t lock, bool dma, + bool is_write) { uint8_t *p; mapcache_lock(mapcache); - p = xen_map_cache_unlocked(mapcache, phys_addr, size, lock, dma); + p = xen_map_cache_unlocked(mapcache, phys_addr, size, lock, dma, is_write); mapcache_unlock(mapcache); return p; } diff --git a/include/sysemu/xen-mapcache.h b/include/sysemu/xen-mapcache.h index 10c2e3082a..1ec9e66752 100644 --- a/include/sysemu/xen-mapcache.h +++ b/include/sysemu/xen-mapcache.h @@ -18,8 +18,9 @@ typedef hwaddr (*phys_offset_to_gaddr_t)(hwaddr phys_offset, void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque); -uint8_t *xen_map_cache(hwaddr phys_addr, hwaddr size, - uint8_t lock, bool dma); +uint8_t *xen_map_cache(MemoryRegion *mr, hwaddr phys_addr, hwaddr size, + uint8_t lock, bool dma, + bool is_write); ram_addr_t xen_ram_addr_from_mapcache(void *ptr); void xen_invalidate_map_cache_entry(uint8_t *buffer); void xen_invalidate_map_cache(void); @@ -33,10 +34,12 @@ static inline void xen_map_cache_init(phys_offset_to_gaddr_t f, { } -static inline uint8_t *xen_map_cache(hwaddr phys_addr, +static inline uint8_t *xen_map_cache(MemoryRegion *mr, + hwaddr phys_addr, hwaddr size, uint8_t lock, - bool dma) + bool dma, + bool is_write) { abort(); } diff --git a/system/physmem.c b/system/physmem.c index f114b972a5..ad7a8c7d95 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -2190,11 +2190,22 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) /* * Return a host pointer to guest's ram. + * For Xen, foreign mappings get created if they don't already exist. + * + * @block: block for the RAM to lookup (optional and may be NULL). + * @addr: address within the memory region. + * @size: pointer to requested size (optional and may be NULL). + * size may get modified and return a value smaller than + * what was requested. + * @lock: wether to lock the mapping in xen-mapcache until invalidated. + * @is_write: hint wether to map RW or RO in the xen-mapcache. + * (optional and may always be set to true). * * Called within RCU critical section. */ static void *qemu_ram_ptr_length(RAMBlock *block, ram_addr_t addr, - hwaddr *size, bool lock) + hwaddr *size, bool lock, + bool is_write) { hwaddr len = 0; @@ -2217,10 +2228,13 @@ 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, len, lock, lock); + return xen_map_cache(block->mr, addr, len, lock, lock, + is_write); } - block->host = xen_map_cache(block->offset, block->max_length, 1, lock); + block->host = xen_map_cache(block->mr, block->offset, + block->max_length, 1, + lock, is_write); } return ramblock_ptr(block, addr); @@ -2236,7 +2250,7 @@ static void *qemu_ram_ptr_length(RAMBlock *block, ram_addr_t addr, */ void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr) { - return qemu_ram_ptr_length(ram_block, addr, NULL, false); + return qemu_ram_ptr_length(ram_block, addr, NULL, false, true); } /* Return the offset of a hostpointer within a ramblock */ @@ -2746,7 +2760,7 @@ static MemTxResult flatview_write_continue_step(MemTxAttrs attrs, } else { /* RAM case */ uint8_t *ram_ptr = qemu_ram_ptr_length(mr->ram_block, mr_addr, l, - false); + false, true); memmove(ram_ptr, buf, *l); invalidate_and_set_dirty(mr, mr_addr, *l); @@ -2839,7 +2853,7 @@ static MemTxResult flatview_read_continue_step(MemTxAttrs attrs, uint8_t *buf, } else { /* RAM case */ uint8_t *ram_ptr = qemu_ram_ptr_length(mr->ram_block, mr_addr, l, - false); + false, false); memcpy(buf, ram_ptr, *l); @@ -3233,7 +3247,7 @@ void *address_space_map(AddressSpace *as, *plen = flatview_extend_translation(fv, addr, len, mr, xlat, l, is_write, attrs); fuzz_dma_read_cb(addr, *plen, mr); - return qemu_ram_ptr_length(mr->ram_block, xlat, plen, true); + return qemu_ram_ptr_length(mr->ram_block, xlat, plen, true, is_write); } /* Unmaps a memory region previously mapped by address_space_map(). @@ -3329,7 +3343,8 @@ int64_t address_space_cache_init(MemoryRegionCache *cache, l = flatview_extend_translation(cache->fv, addr, len, mr, cache->xlat, l, is_write, MEMTXATTRS_UNSPECIFIED); - cache->ptr = qemu_ram_ptr_length(mr->ram_block, cache->xlat, &l, true); + cache->ptr = qemu_ram_ptr_length(mr->ram_block, cache->xlat, &l, true, + is_write); } else { cache->ptr = NULL; } From patchwork Tue Apr 30 16:49:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649670 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A73C4C4345F for ; Tue, 30 Apr 2024 16:52:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qhA-0000B7-Ut; Tue, 30 Apr 2024 12:51:10 -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 1s1qgj-0006j9-UO for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:42 -0400 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgh-00065c-5q for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:41 -0400 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2dd615b6c44so64614881fa.0 for ; Tue, 30 Apr 2024 09:50:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495835; x=1715100635; 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=+Sw3MC4uOQJ6IvvUC7PiIJPbknZwiSjSO/ejkDz0sxs=; b=ngx5MLjEbnBQO9u3gSOpxCaX0xqWwPvY814oKXAUp1fbebqV2eujJkQEr+IqYBwXrM EDXpNTFEhoqWQheEWS6RdzFd9DhN96z9WfEEAtChL1oPl08YvwjYAxdDzIcokAyZ397t oeviSY6B8aR3vUafw1fBbBYKbB02Uj8nBYvHlXPFWZ26ZztpH0cTdV8nRIm4RlOmrz0g nWYD1beXTzqxEwLxnS2SHFJhbh5E3Q9qG3lNF5/VrTyljXhR8u9HVH2C7jGWncUrKVNL IA7W6GFRr6GXXSvZQ3eT2tz//b6E1mkWnUMllcAdQcn73h+ELEMl6sgE9RR3WX0vp8JX Hasw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495835; x=1715100635; 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=+Sw3MC4uOQJ6IvvUC7PiIJPbknZwiSjSO/ejkDz0sxs=; b=EjrZBFaS7KDOy/8E4FkjQE+l7m5epV8hH/wG/Ba4HDKaYuczwHXlRgvfklpRcrTpAj +JBYaTp+msrI8+bWQskyss+dQjPZg5s/lKd+s6yI0pQWojIWKEXHVQALkmJ2JGc7zk/1 qbmpW5dnKai882phos6HiAcuDZPsldJFXejlYyJpyMJVjQBbBYkemTwZFOETD666Qrzb JfEP2ks6oCTShBP3pyZNRaX6FlgmeIZQjckIwoTJcgqBIgYut1NUOVWUenP+p0b+voZl MdiaBGjxbghWmPCjMuBiZAaNmNEsl79uegSw1U+zpOivmnko1jWl+Rfbg03KTtbBrero HlPQ== X-Gm-Message-State: AOJu0Yxl6uIl/HtdX7CsW3rSBCRQgdUFBvj6JBphCs9Gl2+4DWfWVPZO d7nnFEcT9NRjcqQvs1qOtsDiew7rl1Z86bxtaTAQltmOArRYRTxomW0Lsi/J X-Google-Smtp-Source: AGHT+IE03+GLFOiYCtv0tW5oxF/oyJb6HtkdKUGHKboh4aC+T/4yDlCy2Erx7BwyTDTkHUDhKykO+A== X-Received: by 2002:a2e:968e:0:b0:2e0:e410:28d5 with SMTP id q14-20020a2e968e000000b002e0e41028d5mr195041lji.52.1714495834937; Tue, 30 Apr 2024 09:50:34 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id u2-20020a2e8442000000b002d8744903ebsm3873436ljh.68.2024.04.30.09.50.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:33 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony Perard , Paul Durrant , Paolo Bonzini , Peter Xu , David Hildenbrand , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , xen-devel@lists.xenproject.org Subject: [PATCH v4 14/17] xen: Add xen_mr_is_memory() Date: Tue, 30 Apr 2024 18:49:36 +0200 Message-Id: <20240430164939.925307-15-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22e; envelope-from=edgar.iglesias@gmail.com; helo=mail-lj1-x22e.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, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Edgar E. Iglesias" Add xen_mr_is_memory() to abstract away tests for the xen_memory MR. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini Acked-by: David Hildenbrand --- hw/xen/xen-hvm-common.c | 8 +++++++- include/sysemu/xen.h | 8 ++++++++ system/physmem.c | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c index 1627da7398..0267b88d26 100644 --- a/hw/xen/xen-hvm-common.c +++ b/hw/xen/xen-hvm-common.c @@ -12,6 +12,12 @@ MemoryRegion xen_memory; +/* Check for xen memory. */ +bool xen_mr_is_memory(MemoryRegion *mr) +{ + return mr == &xen_memory; +} + void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, Error **errp) { @@ -28,7 +34,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, return; } - if (mr == &xen_memory) { + if (xen_mr_is_memory(mr)) { return; } diff --git a/include/sysemu/xen.h b/include/sysemu/xen.h index 754ec2e6cb..dc72f83bcb 100644 --- a/include/sysemu/xen.h +++ b/include/sysemu/xen.h @@ -34,6 +34,8 @@ void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length); void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, struct MemoryRegion *mr, Error **errp); +bool xen_mr_is_memory(MemoryRegion *mr); + #else /* !CONFIG_XEN_IS_POSSIBLE */ #define xen_enabled() 0 @@ -47,6 +49,12 @@ static inline void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, g_assert_not_reached(); } +static inline bool xen_mr_is_memory(MemoryRegion *mr) +{ + g_assert_not_reached(); + return false; +} + #endif /* CONFIG_XEN_IS_POSSIBLE */ #endif diff --git a/system/physmem.c b/system/physmem.c index ad7a8c7d95..1a5ffcba2a 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -2227,7 +2227,7 @@ static void *qemu_ram_ptr_length(RAMBlock *block, ram_addr_t addr, * because we don't want to map the entire memory in QEMU. * In that case just map the requested area. */ - if (block->offset == 0) { + if (xen_mr_is_memory(block->mr)) { return xen_map_cache(block->mr, addr, len, lock, lock, is_write); } From patchwork Tue Apr 30 16:49:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649679 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3C244C4345F for ; Tue, 30 Apr 2024 16:53:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qhJ-0000nb-5q; Tue, 30 Apr 2024 12:51:17 -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 1s1qgl-00075V-Sg for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:43 -0400 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgi-000660-HH for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:43 -0400 Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-516d68d7a8bso5469257e87.1 for ; Tue, 30 Apr 2024 09:50:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495836; x=1715100636; 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=x1O0c3lbCIPcVTDP2OG2o9vVTYuu5kyg6TUhLFf8SY0=; b=GTyCqx+hWaBOZWEH2w3Deo0TtW73/V1l5pLYKXyxCJQYF76939gEZ4p+gDMR6UKmRs R2qOGD+dM+qOqyVsLyuylpnIVvRA600xtfxP9ScLUr0diJ7I7ALFa8kKVYdAIZatCaSR JIWghPegpquToD/gR1Fg7hlRgoyhQb7MMMckNiUNZsruU9LuSloPv2ZGWSJWmKzQHETa DsxfHHG2yzKAUoM4rVHEYlj12oS1pP5oxY29JwtKnSm+qL26HJNmIzeAQh60DEX4a2CL quUDttIbB4dlZ3iCVL0wO40NqS8q3KWAOjjiGDlIQPQrkvSzupzKbQRbo6tnOuuh+AJs HlBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495836; x=1715100636; 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=x1O0c3lbCIPcVTDP2OG2o9vVTYuu5kyg6TUhLFf8SY0=; b=fLfMjnpEvDdZQymDv+Z/zvdRALu8riO1JkajuJ9v6Nz/HRODd5xbtZrVhohToKFC4e bWv7kK3pXEqSXmpyjME3xGWMtLY/91m2J+TiVPFgQ/QLGJwpoC3tHR+m3elGzs2y5Fq0 Fd/xzNtI9uaIAaCTKtD8edzFG0JzfqB2gQcEIvk5mMiuAM9o/xkE8pmR1EXx4eOYMayE hxE+t0S3qnrBcXwxrqy92ajJ8oQtyev96h+15UNjEi+AfFp+9I7nV7pqDNLsx1oMwHKV fZZHCFlXzc/xdpSCKTgSfAg377g/r4nK2ETQ8583qwFD2//HSJDLBVDURUZdnLwK70sV T/PQ== X-Gm-Message-State: AOJu0Ywn6gmCOjwV7kzedsEGvyveA1aPpXAskYPI0k8KQv+nMQc3g73F uVC8bmtInbUty3NTZchW65BmnMT1zERB0WgojAiJB81gQS46AfDqakmhfJZW X-Google-Smtp-Source: AGHT+IEvjQlWDNSp7Iep3p7LGdRlo9ppcQEfRdIFgR8UUsJQ+BGno9B+qbCWNATble5SB4/21MS5zA== X-Received: by 2002:a05:6512:21e:b0:51a:bd22:12a7 with SMTP id a30-20020a056512021e00b0051abd2212a7mr1077307lfo.26.1714495836367; Tue, 30 Apr 2024 09:50:36 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id v28-20020ac2593c000000b0051905a9c212sm4531378lfi.195.2024.04.30.09.50.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:35 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony Perard , Paul Durrant , Paolo Bonzini , Peter Xu , David Hildenbrand , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , xen-devel@lists.xenproject.org Subject: [PATCH v4 15/17] xen: mapcache: Remove assumption of RAMBlock with 0 offset Date: Tue, 30 Apr 2024 18:49:37 +0200 Message-Id: <20240430164939.925307-16-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12e; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x12e.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, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Edgar E. Iglesias" The current mapcache assumes that all memory is mapped in a single RAM MR (the first one with offset 0). Remove this assumption and propagate the offset to the mapcache so it can do reverse mappings (from hostptr -> ram_addr). This is in preparation for adding grant mappings. Signed-off-by: Edgar E. Iglesias --- hw/xen/xen-mapcache.c | 25 ++++++++++++++++++------- include/sysemu/xen-mapcache.h | 2 ++ system/physmem.c | 8 ++++---- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index 09b5f36d9c..1b32d0c003 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -43,6 +43,9 @@ typedef struct MapCacheEntry { #define XEN_MAPCACHE_ENTRY_DUMMY (1 << 0) uint8_t flags; hwaddr size; + + /* Keep ram_addr offset for reverse mappings (hostptr -> ram_addr). */ + ram_addr_t ram_offset; struct MapCacheEntry *next; } MapCacheEntry; @@ -165,7 +168,8 @@ static void xen_remap_bucket(MapCache *mc, void *vaddr, hwaddr size, hwaddr address_index, - bool dummy) + bool dummy, + ram_addr_t ram_offset) { uint8_t *vaddr_base; xen_pfn_t *pfns; @@ -244,6 +248,7 @@ static void xen_remap_bucket(MapCache *mc, entry->size = size; entry->valid_mapping = g_new0(unsigned long, BITS_TO_LONGS(size >> XC_PAGE_SHIFT)); + entry->ram_offset = ram_offset; if (dummy) { entry->flags |= XEN_MAPCACHE_ENTRY_DUMMY; @@ -264,6 +269,7 @@ static void xen_remap_bucket(MapCache *mc, static uint8_t *xen_map_cache_unlocked(MapCache *mc, hwaddr phys_addr, hwaddr size, + ram_addr_t ram_offset, uint8_t lock, bool dma, bool is_write) { MapCacheEntry *entry, *pentry = NULL, @@ -335,14 +341,16 @@ tryagain: if (!entry) { entry = g_new0(MapCacheEntry, 1); pentry->next = entry; - xen_remap_bucket(mc, entry, NULL, cache_size, address_index, dummy); + xen_remap_bucket(mc, entry, NULL, cache_size, address_index, dummy, + ram_offset); } else if (!entry->lock) { if (!entry->vaddr_base || entry->paddr_index != address_index || entry->size != cache_size || !test_bits(address_offset >> XC_PAGE_SHIFT, test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { - xen_remap_bucket(mc, entry, NULL, cache_size, address_index, dummy); + xen_remap_bucket(mc, entry, NULL, cache_size, address_index, dummy, + ram_offset); } } @@ -389,13 +397,15 @@ tryagain: uint8_t *xen_map_cache(MemoryRegion *mr, hwaddr phys_addr, hwaddr size, + ram_addr_t ram_addr_offset, uint8_t lock, bool dma, bool is_write) { uint8_t *p; mapcache_lock(mapcache); - p = xen_map_cache_unlocked(mapcache, phys_addr, size, lock, dma, is_write); + p = xen_map_cache_unlocked(mapcache, phys_addr, size, ram_addr_offset, + lock, dma, is_write); mapcache_unlock(mapcache); return p; } @@ -432,7 +442,8 @@ static ram_addr_t xen_ram_addr_from_mapcache_single(MapCache *mc, void *ptr) raddr = RAM_ADDR_INVALID; } else { raddr = (reventry->paddr_index << mc->bucket_shift) + - ((unsigned long) ptr - (unsigned long) entry->vaddr_base); + ((unsigned long) ptr - (unsigned long) entry->vaddr_base) + + entry->ram_offset; } mapcache_unlock(mc); return raddr; @@ -627,8 +638,8 @@ static uint8_t *xen_replace_cache_entry_unlocked(MapCache *mc, trace_xen_replace_cache_entry_dummy(old_phys_addr, new_phys_addr); - xen_remap_bucket(mapcache, entry, entry->vaddr_base, - cache_size, address_index, false); + xen_remap_bucket(mc, entry, entry->vaddr_base, + cache_size, address_index, false, entry->ram_offset); if (!test_bits(address_offset >> XC_PAGE_SHIFT, test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { diff --git a/include/sysemu/xen-mapcache.h b/include/sysemu/xen-mapcache.h index 1ec9e66752..b5e3ea1bc0 100644 --- a/include/sysemu/xen-mapcache.h +++ b/include/sysemu/xen-mapcache.h @@ -19,6 +19,7 @@ typedef hwaddr (*phys_offset_to_gaddr_t)(hwaddr phys_offset, void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque); uint8_t *xen_map_cache(MemoryRegion *mr, hwaddr phys_addr, hwaddr size, + ram_addr_t ram_addr_offset, uint8_t lock, bool dma, bool is_write); ram_addr_t xen_ram_addr_from_mapcache(void *ptr); @@ -37,6 +38,7 @@ static inline void xen_map_cache_init(phys_offset_to_gaddr_t f, static inline uint8_t *xen_map_cache(MemoryRegion *mr, hwaddr phys_addr, hwaddr size, + ram_addr_t ram_addr_offset, uint8_t lock, bool dma, bool is_write) diff --git a/system/physmem.c b/system/physmem.c index 1a5ffcba2a..5b16eeccca 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -2228,13 +2228,13 @@ static void *qemu_ram_ptr_length(RAMBlock *block, ram_addr_t addr, * In that case just map the requested area. */ if (xen_mr_is_memory(block->mr)) { - return xen_map_cache(block->mr, addr, len, lock, lock, - is_write); + return xen_map_cache(block->mr, addr, len, block->offset, + lock, lock, is_write); } block->host = xen_map_cache(block->mr, block->offset, - block->max_length, 1, - lock, is_write); + block->max_length, 0, + 1, lock, is_write); } return ramblock_ptr(block, addr); From patchwork Tue Apr 30 16:49:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B9246C4345F for ; Tue, 30 Apr 2024 16:51:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qhM-0001NA-Pe; Tue, 30 Apr 2024 12:51:22 -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 1s1qgm-00077r-5H for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:44 -0400 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgi-000663-Co for qemu-devel@nongnu.org; Tue, 30 Apr 2024 12:50:43 -0400 Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-516d3a470d5so7412449e87.3 for ; Tue, 30 Apr 2024 09:50:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495838; x=1715100638; 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=vn3tcKqblBChMiw5dB8ShfVGNrZaPd3rYTApf1hrAiw=; b=Ygp2hBJXljeh7TqG2ggfJCFpOv0PbWg4K1jatbUdVcNdsogcS8E3XVJPVXmieZL1aY AFW8GT2taoTqpD1Z2GRdLOdCZyVOEXsQF2Qt1ql1x3R7pDDcK7ON6ftnfcUNcVpjeO3A GKJj6Qz9pYotk5v38TWGpea4R/+3I8VFMpxmo/oCeLeP7U64SJi1qqqRj+zaPZSUds+1 2xI4KgYa0uqTPaM7SVGPW15AE51n40iRsNyb12IujXpyUqY55zgxk7Q7z7KMq/PEjBta 9CT0FSwmIbUiIObO7oZIA8P1emXw/QzNIz5uRANrqFdC6A7p4BFluwEwgS73VVKKjc+3 jAsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495838; x=1715100638; 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=vn3tcKqblBChMiw5dB8ShfVGNrZaPd3rYTApf1hrAiw=; b=jAWdKb2PhKskqB4pszDPWiWc9jz1hltLPKkW0pJKKfC0NrHFMkkhSOfvVK+zJcoK9x M01AGqp2VfU9mOmbldpt9GVZ8MarW1rOaGvCVw9apLfZ4Uc/JHL4NQaDd61m+SAAEugF eO9aUM9M0SP4TEdGsBJeenu0OZejDytRsb2alIucI6du0oVrvr9EFeU8hD4njuQXRwz8 TNXgIxNQvN+oeAKkjEZsdJoWG+siXF2WZjYpDJfdJQCDqvsryji/T193K5J2TpYL/R6A KKl++XFOA3P5duI8fhvE1UzCV/ioFt4oM34XYpbLWCpUB88hs6AoKSOMDZSmqY2WZhmN vi7g== X-Gm-Message-State: AOJu0Yyx/I6oOyGg5hog2FV7hB1PXGRjalRjkMKcPx7u3BQvraK8jaPr oVSHL+m46+/Vy+2X7X6YQVeV2CgBwcqwt15Fh96CyJAg6we08I2qKCURRTP/ X-Google-Smtp-Source: AGHT+IH+N37LZPc4kKYgU8RKO/wgJWlfGkar8G/uX+MD1mhqCYFMpxecUBuATrsbvHxL9ZjSvBSY3g== X-Received: by 2002:ac2:5edd:0:b0:51d:ed1:b44c with SMTP id d29-20020ac25edd000000b0051d0ed1b44cmr34799lfq.19.1714495837873; Tue, 30 Apr 2024 09:50:37 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id i18-20020ac25232000000b0051b4991557bsm3044590lfl.275.2024.04.30.09.50.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:37 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony Perard , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v4 16/17] xen: mapcache: Add support for grant mappings Date: Tue, 30 Apr 2024 18:49:38 +0200 Message-Id: <20240430164939.925307-17-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::132; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x132.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, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Edgar E. Iglesias" Add a second mapcache for grant mappings. The mapcache for grants needs to work with XC_PAGE_SIZE granularity since we can't map larger ranges than what has been granted to us. Like with foreign mappings (xen_memory), machines using grants are expected to initialize the xen_grants MR and map it into their address-map accordingly. Signed-off-by: Edgar E. Iglesias --- hw/xen/xen-hvm-common.c | 12 ++- hw/xen/xen-mapcache.c | 158 +++++++++++++++++++++++++------- include/hw/xen/xen-hvm-common.h | 3 + include/sysemu/xen.h | 7 ++ 4 files changed, 145 insertions(+), 35 deletions(-) diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c index 0267b88d26..fdec400491 100644 --- a/hw/xen/xen-hvm-common.c +++ b/hw/xen/xen-hvm-common.c @@ -10,12 +10,18 @@ #include "hw/boards.h" #include "hw/xen/arch_hvm.h" -MemoryRegion xen_memory; +MemoryRegion xen_memory, xen_grants; -/* Check for xen memory. */ +/* Check for any kind of xen memory, foreign mappings or grants. */ bool xen_mr_is_memory(MemoryRegion *mr) { - return mr == &xen_memory; + return mr == &xen_memory || mr == &xen_grants; +} + +/* Check specifically for grants. */ +bool xen_mr_is_grants(MemoryRegion *mr) +{ + return mr == &xen_grants; } void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index 1b32d0c003..96cd68e28d 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -14,6 +14,7 @@ #include +#include "hw/xen/xen-hvm-common.h" #include "hw/xen/xen_native.h" #include "qemu/bitmap.h" @@ -21,6 +22,8 @@ #include "sysemu/xen-mapcache.h" #include "trace.h" +#include +#include #if HOST_LONG_BITS == 32 # define MCACHE_MAX_SIZE (1UL<<31) /* 2GB Cap */ @@ -41,6 +44,7 @@ typedef struct MapCacheEntry { unsigned long *valid_mapping; uint32_t lock; #define XEN_MAPCACHE_ENTRY_DUMMY (1 << 0) +#define XEN_MAPCACHE_ENTRY_GRANT (1 << 1) uint8_t flags; hwaddr size; @@ -74,6 +78,8 @@ typedef struct MapCache { } MapCache; static MapCache *mapcache; +static MapCache *mapcache_grants; +static xengnttab_handle *xen_region_gnttabdev; static inline void mapcache_lock(MapCache *mc) { @@ -132,6 +138,12 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque) unsigned long max_mcache_size; unsigned int bucket_shift; + xen_region_gnttabdev = xengnttab_open(NULL, 0); + if (xen_region_gnttabdev == NULL) { + error_report("mapcache: Failed to open gnttab device"); + exit(EXIT_FAILURE); + } + if (HOST_LONG_BITS == 32) { bucket_shift = 16; } else { @@ -160,6 +172,15 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque) mapcache = xen_map_cache_init_single(f, opaque, bucket_shift, max_mcache_size); + + /* + * Grant mappings must use XC_PAGE_SIZE granularity since we can't + * map anything beyond the number of pages granted to us. + */ + mapcache_grants = xen_map_cache_init_single(f, opaque, + XC_PAGE_SHIFT, + max_mcache_size); + setrlimit(RLIMIT_AS, &rlimit_as); } @@ -169,17 +190,25 @@ static void xen_remap_bucket(MapCache *mc, hwaddr size, hwaddr address_index, bool dummy, + bool grant, + bool grant_is_write, + hwaddr grant_ref, ram_addr_t ram_offset) { uint8_t *vaddr_base; - xen_pfn_t *pfns; + uint32_t *refs = NULL; + xen_pfn_t *pfns = NULL; int *err; unsigned int i; hwaddr nb_pfn = size >> XC_PAGE_SHIFT; trace_xen_remap_bucket(address_index); - pfns = g_new0(xen_pfn_t, nb_pfn); + if (grant) { + refs = g_new0(uint32_t, nb_pfn); + } else { + pfns = g_new0(xen_pfn_t, nb_pfn); + } err = g_new0(int, nb_pfn); if (entry->vaddr_base != NULL) { @@ -208,21 +237,45 @@ static void xen_remap_bucket(MapCache *mc, g_free(entry->valid_mapping); entry->valid_mapping = NULL; - for (i = 0; i < nb_pfn; i++) { - pfns[i] = (address_index << (mc->bucket_shift - XC_PAGE_SHIFT)) + i; + if (grant) { + for (i = 0; i < nb_pfn; i++) { + refs[i] = grant_ref + i; + } + } else { + for (i = 0; i < nb_pfn; i++) { + pfns[i] = (address_index << (mc->bucket_shift - XC_PAGE_SHIFT)) + i; + } } - /* - * If the caller has requested the mapping at a specific address use - * MAP_FIXED to make sure it's honored. - */ + entry->flags &= ~XEN_MAPCACHE_ENTRY_GRANT; + if (!dummy) { - vaddr_base = xenforeignmemory_map2(xen_fmem, xen_domid, vaddr, - PROT_READ | PROT_WRITE, - vaddr ? MAP_FIXED : 0, - nb_pfn, pfns, err); + if (grant) { + int prot = PROT_READ; + + if (grant_is_write) { + prot |= PROT_WRITE; + } + + entry->flags |= XEN_MAPCACHE_ENTRY_GRANT; + assert(vaddr == NULL); + vaddr_base = xengnttab_map_domain_grant_refs(xen_region_gnttabdev, + nb_pfn, + xen_domid, refs, + prot); + } else { + /* + * If the caller has requested the mapping at a specific address use + * MAP_FIXED to make sure it's honored. + */ + vaddr_base = xenforeignmemory_map2(xen_fmem, xen_domid, vaddr, + PROT_READ | PROT_WRITE, + vaddr ? MAP_FIXED : 0, + nb_pfn, pfns, err); + } if (vaddr_base == NULL) { - perror("xenforeignmemory_map2"); + perror(grant ? "xengnttab_map_domain_grant_refs" + : "xenforeignmemory_map2"); exit(-1); } } else { @@ -263,6 +316,7 @@ static void xen_remap_bucket(MapCache *mc, } } + g_free(refs); g_free(pfns); g_free(err); } @@ -270,10 +324,12 @@ static void xen_remap_bucket(MapCache *mc, static uint8_t *xen_map_cache_unlocked(MapCache *mc, hwaddr phys_addr, hwaddr size, ram_addr_t ram_offset, - uint8_t lock, bool dma, bool is_write) + uint8_t lock, bool dma, + bool grant, bool is_write) { MapCacheEntry *entry, *pentry = NULL, *free_entry = NULL, *free_pentry = NULL; + hwaddr grant_ref = phys_addr >> XC_PAGE_SHIFT; hwaddr address_index; hwaddr address_offset; hwaddr cache_size = size; @@ -342,7 +398,7 @@ tryagain: entry = g_new0(MapCacheEntry, 1); pentry->next = entry; xen_remap_bucket(mc, entry, NULL, cache_size, address_index, dummy, - ram_offset); + grant, is_write, grant_ref, ram_offset); } else if (!entry->lock) { if (!entry->vaddr_base || entry->paddr_index != address_index || entry->size != cache_size || @@ -350,7 +406,7 @@ tryagain: test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { xen_remap_bucket(mc, entry, NULL, cache_size, address_index, dummy, - ram_offset); + grant, is_write, grant_ref, ram_offset); } } @@ -401,12 +457,28 @@ uint8_t *xen_map_cache(MemoryRegion *mr, uint8_t lock, bool dma, bool is_write) { + bool grant = xen_mr_is_grants(mr); + MapCache *mc = grant ? mapcache_grants : mapcache; uint8_t *p; - mapcache_lock(mapcache); - p = xen_map_cache_unlocked(mapcache, phys_addr, size, ram_addr_offset, - lock, dma, is_write); - mapcache_unlock(mapcache); + if (grant) { + /* + * Grants are only supported via address_space_map(). Anything + * else is considered a user/guest error. + * + * QEMU generally doesn't expect these mappings to ever fail, so + * if this happens we report an error message and abort(). + */ + if (!lock) { + error_report("Trying access a grant reference without mapping it."); + abort(); + } + } + + mapcache_lock(mc); + p = xen_map_cache_unlocked(mc, phys_addr, size, ram_addr_offset, + lock, dma, grant, is_write); + mapcache_unlock(mc); return p; } @@ -451,7 +523,14 @@ static ram_addr_t xen_ram_addr_from_mapcache_single(MapCache *mc, void *ptr) ram_addr_t xen_ram_addr_from_mapcache(void *ptr) { - return xen_ram_addr_from_mapcache_single(mapcache, ptr); + ram_addr_t addr; + + addr = xen_ram_addr_from_mapcache_single(mapcache, ptr); + if (addr == RAM_ADDR_INVALID) { + addr = xen_ram_addr_from_mapcache_single(mapcache_grants, ptr); + } + + return addr; } static void xen_invalidate_map_cache_entry_unlocked(MapCache *mc, @@ -504,9 +583,14 @@ static void xen_invalidate_map_cache_entry_unlocked(MapCache *mc, } ram_block_notify_remove(entry->vaddr_base, entry->size, entry->size); - if (munmap(entry->vaddr_base, entry->size) != 0) { - perror("unmap fails"); - exit(-1); + if (entry->flags & XEN_MAPCACHE_ENTRY_GRANT) { + xengnttab_unmap(xen_region_gnttabdev, entry->vaddr_base, + (entry->size + mc->bucket_size - 1) >> mc->bucket_shift); + } else { + if (munmap(entry->vaddr_base, entry->size) != 0) { + perror("unmap fails"); + exit(-1); + } } if (pentry) { pentry->next = entry->next; @@ -522,14 +606,24 @@ typedef struct XenMapCacheData { uint8_t *buffer; } XenMapCacheData; +static void xen_invalidate_map_cache_entry_single(MapCache *mc, uint8_t *buffer) +{ + mapcache_lock(mc); + xen_invalidate_map_cache_entry_unlocked(mc, buffer); + mapcache_unlock(mc); +} + +static void xen_invalidate_map_cache_entry_all(uint8_t *buffer) +{ + xen_invalidate_map_cache_entry_single(mapcache, buffer); + xen_invalidate_map_cache_entry_single(mapcache_grants, buffer); +} + static void xen_invalidate_map_cache_entry_bh(void *opaque) { XenMapCacheData *data = opaque; - mapcache_lock(mapcache); - xen_invalidate_map_cache_entry_unlocked(mapcache, data->buffer); - mapcache_unlock(mapcache); - + xen_invalidate_map_cache_entry_all(data->buffer); aio_co_wake(data->co); } @@ -544,9 +638,7 @@ void coroutine_mixed_fn xen_invalidate_map_cache_entry(uint8_t *buffer) xen_invalidate_map_cache_entry_bh, &data); qemu_coroutine_yield(); } else { - mapcache_lock(mapcache); - xen_invalidate_map_cache_entry_unlocked(mapcache, buffer); - mapcache_unlock(mapcache); + xen_invalidate_map_cache_entry_all(buffer); } } @@ -598,6 +690,7 @@ void xen_invalidate_map_cache(void) bdrv_drain_all(); xen_invalidate_map_cache_single(mapcache); + xen_invalidate_map_cache_single(mapcache_grants); } static uint8_t *xen_replace_cache_entry_unlocked(MapCache *mc, @@ -639,7 +732,8 @@ static uint8_t *xen_replace_cache_entry_unlocked(MapCache *mc, trace_xen_replace_cache_entry_dummy(old_phys_addr, new_phys_addr); xen_remap_bucket(mc, entry, entry->vaddr_base, - cache_size, address_index, false, entry->ram_offset); + cache_size, address_index, false, + false, false, 0, entry->ram_offset); if (!test_bits(address_offset >> XC_PAGE_SHIFT, test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { diff --git a/include/hw/xen/xen-hvm-common.h b/include/hw/xen/xen-hvm-common.h index 65a51aac2e..3d796235dc 100644 --- a/include/hw/xen/xen-hvm-common.h +++ b/include/hw/xen/xen-hvm-common.h @@ -16,6 +16,7 @@ #include extern MemoryRegion xen_memory; +extern MemoryRegion xen_grants; extern MemoryListener xen_io_listener; extern DeviceListener xen_device_listener; @@ -29,6 +30,8 @@ extern DeviceListener xen_device_listener; do { } while (0) #endif +#define XEN_GRANT_ADDR_OFF (1ULL << 63) + static inline uint32_t xen_vcpu_eport(shared_iopage_t *shared_page, int i) { return shared_page->vcpu_ioreq[i].vp_eport; diff --git a/include/sysemu/xen.h b/include/sysemu/xen.h index dc72f83bcb..19dccf4d71 100644 --- a/include/sysemu/xen.h +++ b/include/sysemu/xen.h @@ -35,6 +35,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, struct MemoryRegion *mr, Error **errp); bool xen_mr_is_memory(MemoryRegion *mr); +bool xen_mr_is_grants(MemoryRegion *mr); #else /* !CONFIG_XEN_IS_POSSIBLE */ @@ -55,6 +56,12 @@ static inline bool xen_mr_is_memory(MemoryRegion *mr) return false; } +static inline bool xen_mr_is_grants(MemoryRegion *mr) +{ + g_assert_not_reached(); + return false; +} + #endif /* CONFIG_XEN_IS_POSSIBLE */ #endif From patchwork Tue Apr 30 16:49:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 13649680 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 65C68C4345F for ; Tue, 30 Apr 2024 16:53:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1qhK-00015T-Qb; Tue, 30 Apr 2024 12:51:19 -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 1s1qgl-00075i-Ti; Tue, 30 Apr 2024 12:50:43 -0400 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1qgk-00066Q-3n; Tue, 30 Apr 2024 12:50:43 -0400 Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2db13ca0363so95568181fa.3; Tue, 30 Apr 2024 09:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495840; x=1715100640; 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=hzipat9jfi0juaK8DzS+Vl1mWo37mk7jTOq9poKtbag=; b=eyp4yrWJ3EK3PlXaY7Z8w9cc9tNZdj9yTSZDBKynFcBOAniFRHRGZ/Dvt5JNjIhKym NMwHb733HRfSALHk8Tkh1kHm4m5nLNUH31/53VVXuWYWtC0mfxa0aYqNCgmSBXa4Xnek mNbdw1RXAS1lSr/YG4Bp7URrnXLJy1nX7/MXkA5MK07iPVYAIDnsrc+KKQvs9hz5C286 +OQ2u0pTFqQEjNGhvcbHKBYqu65/nf6W+MJrjoDeelAQ/X0wG+O44KKiz7p2G1gOT1O/ q7FZi/PuGbr/bJfuhudoYtKfRrnoUQ+yjuKEqn7CcBXvQh4mn2C2LtLN0gGGgiS15P2r CCZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714495840; x=1715100640; 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=hzipat9jfi0juaK8DzS+Vl1mWo37mk7jTOq9poKtbag=; b=fQcY8NNkayUY5rTV23s3C5nu9JoWhkfe5+tQsAIgqyR0KzF1M/oLS70l0JLH27JYHZ CkydfqPax9D3TS+F86OvF/Jy/D3LXxyQMQYDasw1KLyDtUXyVOjMQ3wEzW9QmqhED13L 2oh7L9zeYn145qww/AaHQ7WWgulnKsga31YxakAek7aH/EdWo9zyW0JX3VQbyuM+dr7t oCZ8DI2pGzLFJjXUNNuk+uRP/x8XfqoPxyBfzR2f6oZsJHaenJAcd8RJo555hSocQCwM O8a3b1I4I0PGHLUMt72XojAyRhMkwN1HMwLik10D2is35ytVFyJuRRQ803UVMr2DvOGy iRSg== X-Forwarded-Encrypted: i=1; AJvYcCWHMchipmxIb6VMi/cEdMdiImZd659zMGLNvXukmKal8q5fbUxO2dVxiBaPsp7jblUvlq6u9N+795fFXdqaT0Xq8WEy X-Gm-Message-State: AOJu0YxycYJar5i1RzSGfFQcWV11zFfG+wFBR47ecIyMcNm/+VoN2yYI Hl2dyukx94j2mBsYztKDs3Fh00OHvDMP56BI46L+nDLz19sHnNdjpR37iqOf X-Google-Smtp-Source: AGHT+IE5I0psn0q10FnxlP3BV+p1w3O9Axel6EVi2qAM89LYPmK64ZWaL7a/7ZWVOltawOLUNQAxyg== X-Received: by 2002:a19:ad09:0:b0:51c:732e:4e1a with SMTP id t9-20020a19ad09000000b0051c732e4e1amr26295lfc.68.1714495839514; Tue, 30 Apr 2024 09:50:39 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id c15-20020a19760f000000b0051c144062eesm2198113lff.273.2024.04.30.09.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 09:50:38 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Peter Maydell , qemu-arm@nongnu.org Subject: [PATCH v4 17/17] hw/arm: xen: Enable use of grant mappings Date: Tue, 30 Apr 2024 18:49:39 +0200 Message-Id: <20240430164939.925307-18-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240430164939.925307-1-edgar.iglesias@gmail.com> References: <20240430164939.925307-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::231; envelope-from=edgar.iglesias@gmail.com; helo=mail-lj1-x231.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, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Edgar E. Iglesias" Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini --- hw/arm/xen_arm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c index 15fa7dfa84..6fad829ede 100644 --- a/hw/arm/xen_arm.c +++ b/hw/arm/xen_arm.c @@ -125,6 +125,11 @@ static void xen_init_ram(MachineState *machine) GUEST_RAM1_BASE, ram_size[1]); memory_region_add_subregion(sysmem, GUEST_RAM1_BASE, &ram_hi); } + + /* Setup support for grants. */ + memory_region_init_ram(&xen_grants, NULL, "xen.grants", block_len, + &error_fatal); + memory_region_add_subregion(sysmem, XEN_GRANT_ADDR_OFF, &xen_grants); } void arch_handle_ioreq(XenIOState *state, ioreq_t *req)