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: 13649626 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 6EB4FC10F16 for ; Tue, 30 Apr 2024 16:50:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.715053.1116511 (Exim 4.92) (envelope-from ) id 1s1qgV-0004Q5-JX; Tue, 30 Apr 2024 16:50:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 715053.1116511; Tue, 30 Apr 2024 16:50:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgV-0004OG-DD; Tue, 30 Apr 2024 16:50:27 +0000 Received: by outflank-mailman (input) for mailman id 715053; Tue, 30 Apr 2024 16:50:26 +0000 Received: from [94.247.172.50] (helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgU-0003oL-Lx for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 16:50:26 +0000 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [2a00:1450:4864:20::22b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b7785fee-0711-11ef-b4bb-af5377834399; Tue, 30 Apr 2024 18:50:14 +0200 (CEST) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2dd6c14d000so73581731fa.0 for ; Tue, 30 Apr 2024 09:50:14 -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) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b7785fee-0711-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495814; x=1715100614; darn=lists.xenproject.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=fEwZHCpuVwYdInTgp+ATzSHvKMD61A0rfFvyC23+fWdzizH95yI1KvoWNv1pnSBGoj qv6ntGYnb6bnU6FMxURJdsrWY8c1ikv1sqGKsUh4Xkm+8a1MCB2Rh+VHqllzq9CyeSJT P6T5mSzsa0VoK+4AM5nYo5MiIRFdN/bxU92rVCreibzlN5rQWu65No5NFQcm3trCSDo8 iOKvRRRrixfF3qUqKsQOOlHu+zZrPbWDbcZT5TrLeu8eqYfJ+fX3AC1D119PlKMiYhoy hd4PgGMvGh9luUmSkaTUVxzSLvT0qSFuUwpZYnVqZB97TbkI/pml4Dr6cT+p9VssDCwN qGfA== 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=d3rEsn4NhSw3iphvcZNpZxpDDxIFjGklJlGp0o2/SNQDlC9mc9f2iNECNLR5BvaG8r Gi4vliZM1Mrv96CymbNlqeErWSS9Aj50L8KdNKd4BrGy5Yez2f88kbqEvxMt+t3N56jI icfbpG/+byTJi9rPUMzoQTvU6nKbx3E7sDesYlP9tc0O9BxPGeQSzXQX3yH+SNiHLdH2 C+nlQZuWvBTW7h8sOdafpEJe7mvHeUDZhWTZ9PvnekhwKq59gRrBAvpd3IjRbMGPxwW2 gXTjX3+L3dyuukbuaJkh0dkk6s6j0RWXN20mGEIr+ctgd2dmapND76i+6uG2flSLFBF3 pKIA== X-Forwarded-Encrypted: i=1; AJvYcCXLBcrfoDyEvm1dc+lrJZlogJbMxLomDJ2G5Xj9aVFg7QiN/AR+++I4apSpbo5stz6eV1OAorBd3hkhcUKUMWyusnePmmTv20ySnboFmvU= X-Gm-Message-State: AOJu0YwfDjLubz6NpAwdRtoNu0VS1nXDpZQ7LbbdcCGO1C8z4J3yuy9V RkNeZi8joXRAW3ul8lvqIh38O5cjHjLL13Uxl8ZitpnIQ3dCXpdf 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) 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 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: 13649624 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 379E1C4345F for ; Tue, 30 Apr 2024 16:50:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.715054.1116516 (Exim 4.92) (envelope-from ) id 1s1qgV-0004Ty-SX; Tue, 30 Apr 2024 16:50:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 715054.1116516; Tue, 30 Apr 2024 16:50:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgV-0004Rv-N5; Tue, 30 Apr 2024 16:50:27 +0000 Received: by outflank-mailman (input) for mailman id 715054; Tue, 30 Apr 2024 16:50:26 +0000 Received: from [94.247.172.50] (helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgU-0003oL-Sr for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 16:50:26 +0000 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [2a00:1450:4864:20::229]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b8959ab7-0711-11ef-b4bb-af5377834399; Tue, 30 Apr 2024 18:50:16 +0200 (CEST) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2e049cfe645so88171fa.0 for ; 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) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b8959ab7-0711-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495816; x=1715100616; darn=lists.xenproject.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=B8gkTf++nosRLAD1kYAg10sBmcwVa5ypMEgmjGLDuAX32jNHABdSZuMuE7TuM/a2rE 5IiaiFBWqThJ5F9mg8ZU+rlWgf/W8xwkWTZug2jhUOrfrkoIFp5bXU12JETI1UrhfCl7 fWI9l1+52nz8q4pNI+TUUsdeQz5+9Tdzl6LnMFs4XGbm+5WhGfZmW0PTUu3tp8lXVPdJ k8BEjX/FrAvPPmcUEztFLy5El34t+6uLHFgZdepbnDI5mtuB34fZ0SnrE5lx7WVP2pPY 9yIu5p6gszD+2hadgBGnogd6mCYGYoUdevpO87cYxrzapKCCKK2h2posK5g3QP/J1vj2 ptPA== 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=d+idKuhHQi1XOUMwezFprvfENQgW3RNOkyq4Rc5InxUqSTltJ/nVFW/uf22t5r4SRs RLOG1GcgzAG7j8BZMq/ygX4ZVsa1QVgeJfrfPd3crthULfWJoEy5JTyzWT+yWor3sqPb E1ZPPGLF3lAvzeLB67GOtpoARpWVha9juoZyhMRxJSuV0EybcCumcud21R3aGAMDU8Pt 0/sYqrdHSQ6mu9XoaJoVUUTm789nk8NfFIhYni6A4EU1NfyCqq4nVyAbONkPDDii4TSY G9sKOek1ndKKTpfR/lWJVnHzLe/o/khnKYRiTnlz6YWuc2lraoOIwmLFwedFJLx+DVvO ajVw== X-Forwarded-Encrypted: i=1; AJvYcCXjZEl9AFXHgGQ+Ytl+XGAQAhp0D2hSmBMEhz1psrNlQpiv5ZVYAz6w8mrGVjoVcV29oyUucmnMvBY0b8f/IjBSSgycMzOJqi2Otedyuvw= X-Gm-Message-State: AOJu0YxODipoV14NcrqujGCTnY7NuvDOgwSVBTVah0I6LlT7UCVg1Grq EOBJmwfThm1ry4SeCjQPWpn21CJewJoK1HBZcL3PkUSHo0lpW4/7 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) 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 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: 13649625 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 37A16C19F4F for ; Tue, 30 Apr 2024 16:50:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.715050.1116485 (Exim 4.92) (envelope-from ) id 1s1qgO-0003og-JQ; Tue, 30 Apr 2024 16:50:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 715050.1116485; Tue, 30 Apr 2024 16:50:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgO-0003oZ-Gd; Tue, 30 Apr 2024 16:50:20 +0000 Received: by outflank-mailman (input) for mailman id 715050; Tue, 30 Apr 2024 16:50:19 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgN-0003oO-Bz for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 16:50:19 +0000 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [2a00:1450:4864:20::236]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b9969a07-0711-11ef-909b-e314d9c70b13; Tue, 30 Apr 2024 18:50:18 +0200 (CEST) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2dac77cdf43so75645131fa.2 for ; Tue, 30 Apr 2024 09:50:18 -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) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b9969a07-0711-11ef-909b-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495818; x=1715100618; darn=lists.xenproject.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=BIrsbAq2AFIajidX8ZlJMr510TnGVF9lbzuSogUmnbg4QHKN90mp3qLP+IvvecL1yt +SX1BkSWd6uCDFct/mclKSL1LM5OWCD1sv/2g3jgjnKLMPlVNU/qaV5DBVdbputkTl3w l5ZN7rKocmgSC7rwvD2K1mp772MFqTHVPLwz8FhYYNPdLPCEzWdtf+4ZMHFQAmQiTXBt SVUIslgldRwlSoqTvgRD4TcikpX8njYqDprf0/EAWl1qZ+egbwf40bYSxF4V3y1q4Tw/ onhl4Q5hUfaVT64fNAm8/6lCj6+4aljYt6L3/PhRpkzUobTlVoCTwgqg9yRungwXv+vi koeQ== 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=bMZUDdgHXGuHc5pPfT0KkfKBY2iN0sV8n3FFy0nZwhW1cZK2mo3oAF1lOBI166I2aW nj2gc17MKKofEenlXFC+lrclkOKZP8jtpsre/Rcz90frv4rd30jE6GV55AzGjk9tgY5o 7wptiVmixC68sXgLXlnbU8tZ4ATAuuiBVyYlGhTnApKZLhAg4tVsLV9qbdCvkky6UmOn Xbam1h/elCjH/yB6HgJwyzC2dCVjm9T/H/scXqNHI+7lgIad+bZL/rpLg6MUW5IC2lio ek8bflx7AoI454ICUvxgf5qKOz4phbdsPFAEHdnctGNM1meeMsLIddvxAqOccF/W4V5U FxSQ== X-Forwarded-Encrypted: i=1; AJvYcCV6ZKjWGbArE0ww8NWpP7SDWz/MqEt6M2A2nhPhuDgKMPvdWrlfV1Vpj6fG60Ny4oTHLWa1tXkO/cRdrR/yx5xATPXDilAU3htjPX/BYtA= X-Gm-Message-State: AOJu0YxaK76NP7rzZNFBZLc4Gnru9l5A4Bq9Gz7r9MilDc7+w4OZhp7N UjkOZK3G8S7dgrSBTKVNTXw9snD8n0tLO1bCcElohiKex81ixZUZ 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) 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 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: 13649629 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 29F1DC25B73 for ; Tue, 30 Apr 2024 16:50:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.715051.1116494 (Exim 4.92) (envelope-from ) id 1s1qgP-00042s-P6; Tue, 30 Apr 2024 16:50:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 715051.1116494; Tue, 30 Apr 2024 16:50:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgP-00042l-MZ; Tue, 30 Apr 2024 16:50:21 +0000 Received: by outflank-mailman (input) for mailman id 715051; Tue, 30 Apr 2024 16:50:20 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgO-0003oO-8D for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 16:50:20 +0000 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [2a00:1450:4864:20::136]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ba7eca0e-0711-11ef-909b-e314d9c70b13; Tue, 30 Apr 2024 18:50:19 +0200 (CEST) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-516d2600569so7363224e87.0 for ; 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) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ba7eca0e-0711-11ef-909b-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495819; x=1715100619; darn=lists.xenproject.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=CP4wnhEgxWoYJDFkX1dZuB35ZWnoJ5OWn0NNf6gJc3Clh9I8iRRV00ck3K5NpwWUi1 Z7WNsmF6nitJVzlsuCcuPqSLKVCTDgcAbsjlwhN1iPDGC10DAt9vdn9p2SQdpFZqM204 jLhmAx2AnbQpjQrd+mQUu4TwYyzXR9JrRlKwE5MBnZ1Y9I8QmQfM/F1FLSjJTpHNfL+W lNhKF18/l/wAA+iyjKkuREKgkAr2PCZRjHah+6y8THQ9+E0NoCC0lMyVGN+oCAywPTT1 KHgTKqGDvgKAq7yj41k1ZqVVRwFACPUHrYuW1eX0l6odnKkUkWTd+3kDTIAo4OTgmXrl 1UEQ== 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=HPC900EL+DkO3B15lW+Qpeg3byzBC0KNKJbLby4FxjkdZf3dS5t+58jbZIYegVVeuV lLD9sOycqOtHgAyTSpBOK69FnidGhQ2ZLd7Nltvxi0NOG2yy6wdgTDe2fX89dOahxsKu IiE3NFd8829GEoCtAzWrCfEdRl1J4fjEk84t99gFB/y7CUSx6Y6pBIwFto/G2dbNMvYb Z5Q8JeiNZVEsrx1o56abRszfo7LcWx/hT7iWtvLXJVm03sGoeWUlq8F3xRu65LwQasTz OGlSTNa2A8im5Tj+6Dszy0e+GaSD8xFXY5Iu+26JP9ekpDkCJQWjfhLvkaZ4vZQ2n8Qa pxHA== X-Forwarded-Encrypted: i=1; AJvYcCX67xOcchdI97JkO/V+mg+nMCoVlakA+SAlnymPcElBBgqEmqN1KBjYZb0dmNUQVAX2Toqr6S+8sAbJ8eWy92T7l50OhX/pzQQkfc1NL2E= X-Gm-Message-State: AOJu0YzVZhN3POhzFdq1gJ+8MqO3AzusQN+m3yT0w2aitj2th+GHCt3F NDe7jiKa9Db3dPxvt7JViSk3BKsO5ixwBiuG1GcM9dHtI295bzT3 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) 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 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: 13649630 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 29EA8C25B10 for ; Tue, 30 Apr 2024 16:50:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.715056.1116542 (Exim 4.92) (envelope-from ) id 1s1qgX-0005AY-Kv; Tue, 30 Apr 2024 16:50:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 715056.1116542; Tue, 30 Apr 2024 16:50:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgX-00058b-Dz; Tue, 30 Apr 2024 16:50:29 +0000 Received: by outflank-mailman (input) for mailman id 715056; Tue, 30 Apr 2024 16:50:28 +0000 Received: from [94.247.172.50] (helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgV-0003oL-Su for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 16:50:27 +0000 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [2a00:1450:4864:20::129]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id bbabb852-0711-11ef-b4bb-af5377834399; Tue, 30 Apr 2024 18:50:21 +0200 (CEST) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-5196fe87775so6618014e87.3 for ; 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) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: bbabb852-0711-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495821; x=1715100621; darn=lists.xenproject.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=LuQ742VUw+vkIfqZxv5gWWnyAs4uVlIPMUOi9VOnVpF2WcdU1h2nI10VNUKCe4H4pv TgRgqT1PcnMpCcg+/OOtzyFtY10oyHryikU7Wxpg8y7IT44KigBCZY7hGeZs6rq5dA3U uMHA3iv7yN9PmYOzQafQa2bxzO1qxMI/Q8Fw+hDlzOFRQIHSJ3oGaCOomQEtrWb35+sy dchR3NJontNUQuOAR9NSeCPaD4UzbwY1PPgGgiU+eQKHHOInCrZp4q8n4R3nr9rPjiOd nLmJtJG7SRG0PNFfsrlaaaMpjEqmLYJlbG+8GLLoxos9ULr12dukbX5PIC8q9BIr/4or mnrQ== 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=TRrQc13rwuoeMLqtRL/f30XKDnHFckXvLRuGmYtH9sSGgHl0k6dzj0dGRh1XyHweFz 8TcmDtKCv83Sy1T19zb2XJnjhp8dWx7L4mJ/Ra0ExXxCeauehde6QJTVOh6bl3PsSA9t JOAkFg0cY0nnlovanTwIgaEWivzYTgm6XoG42WUV7HKrMXCskh3Zg28Og/aYpu3ctEVA buHu9Fs5XAGMhyH5EJff6F1Ao6YugRfgsLJ07WDhMg0Ub5Clko6ov4RriigO3psF23xj +k/9EajyiKzyq+TVV4eWs7VVoC27V5K1TsYR1qDRQcsdwM1BqXmnN6gW34MA+s5YbBsd kxYA== X-Forwarded-Encrypted: i=1; AJvYcCVKGrAu/sa4+UCb/yZuGzCdcTpt48o5vbK198otY8ClGgv7aV6OcCxGUlQoF4H6j6fBzOZB8TNcspmRMGgg80aSL/gTZyA/dRuosnnMBWw= X-Gm-Message-State: AOJu0Yy5hLY7/meWhc3nycHh+40AidgKrjARwO+bgZp11jsrRwC2Q+PR HOiGJHvZL5dGNzk9CBP4PV2gNL+gkw+ImL1q9UZ3pAc97uNPj8HE 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) 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 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: 13649627 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 93982C25B5C for ; Tue, 30 Apr 2024 16:50:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.715057.1116548 (Exim 4.92) (envelope-from ) id 1s1qgY-0005Gy-5B; Tue, 30 Apr 2024 16:50:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 715057.1116548; Tue, 30 Apr 2024 16:50:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgX-0005Fw-TP; Tue, 30 Apr 2024 16:50:29 +0000 Received: by outflank-mailman (input) for mailman id 715057; Tue, 30 Apr 2024 16:50:28 +0000 Received: from [94.247.172.50] (helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgW-0003oL-Sw for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 16:50:28 +0000 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [2a00:1450:4864:20::22b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id bc8309ef-0711-11ef-b4bb-af5377834399; Tue, 30 Apr 2024 18:50:23 +0200 (CEST) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2db101c11beso69152331fa.0 for ; Tue, 30 Apr 2024 09:50:23 -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) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: bc8309ef-0711-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495823; x=1715100623; darn=lists.xenproject.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=I9Z5CReJxpo12aMXxcmq761o+9fQdvNXjP3/UODDLL794TidUhWbvhuj+JNBYcXi82 AigNbNhqflp+nejy9rznB3nH+9f8UXVCILQS7ozv+PJi20cx8CGPq6B4IO/sFc/I40vL CIH+SNQ0Vvz7h30LVeBdmoyKtOCGsXCNX2CJRCjT5ZxN9csumeTI8C5Q6+ru7eCSno+3 tTlWs9XQIQnEUyCd73U6gi3scPWqItAz9yiGVC4MSnB4uh3zoSIOiapUiyx+/K9CvS1v tMbc59kielf2BjHN4PT8l2mtMzOiOAWqh20qjO9FnB8krbvmIzUwapunFkHRVCVTOXFf DJbw== 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=QwwTzG3KME1vDuKFn3wzos4vADHP9YWX+KGhSh3s3BlaLg9iwuugzfI8kyif75zOvk tW4+DXJ9wDiyhvqmS6p8eI4GQw/mEU+B9pij5XqNcHVAgtegZPOHalqSC4l+H7UHY9D4 xU/jjFfSXuIJKW8R8LcppSek7XmiSvAOvJTcH3D1TMMU1UZeFPplPprT0pzv144OY477 zsPm7FKTbTZ8cfYTj7l8NboG1H1+5xokRhMe7smOMxpTIxoo/HLALfvUMG/eJkHaQEcc D7MwZn/81PLAncESgUTGluKhBHNs9NmB/8b7baVt9dZGAAVZrBTUfaBz2hG6Osk/4t/r GsQw== X-Forwarded-Encrypted: i=1; AJvYcCWvs3ZcXioRVSDc7VPpHoscgc1hpxMHuwTUk85EUGGisZqKJI9AeI+4hOrZNYsn1d7PEZDG1bTTQYPXuhN0S7NbY0a+c+Ri6eBGP2dt6ig= X-Gm-Message-State: AOJu0YwcnSipqit3TNfPiMteGYQejXwJ8sX9HJbHNnykGzjKs0FBXJYh YuFNbK/2AI3rL6lmmGXmPxvMq4TyOschgegOAOeI6WLtg+LBqxuR 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) 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 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: 13649631 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 D83A5C25B74 for ; Tue, 30 Apr 2024 16:50:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.715052.1116505 (Exim 4.92) (envelope-from ) id 1s1qgV-0004JE-2X; Tue, 30 Apr 2024 16:50:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 715052.1116505; Tue, 30 Apr 2024 16:50:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgU-0004J7-Ua; Tue, 30 Apr 2024 16:50:26 +0000 Received: by outflank-mailman (input) for mailman id 715052; Tue, 30 Apr 2024 16:50:25 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgT-0003oO-Ic for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 16:50:25 +0000 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [2a00:1450:4864:20::12e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id bdb105fa-0711-11ef-909b-e314d9c70b13; Tue, 30 Apr 2024 18:50:25 +0200 (CEST) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-516d264d0e4so10924e87.0 for ; Tue, 30 Apr 2024 09:50:25 -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) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: bdb105fa-0711-11ef-909b-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495824; x=1715100624; darn=lists.xenproject.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=GHhjqpPSU4kT7Um5onInyv/0qvcJl2zA2c1xkaf/qeq1ZkLjW/hbwXJHt5mZ7OQo+a m9v1BeTZA7V/fpwSIOFb4aHyC1NFXzvvVNCkYfugEHaNX8a8BJRzn0nB0qu7dFLf8VP+ mcr8saXq0H5AqcWzah9soVrtaivnyeuTraY06weik3fSC3d/FrXOPhRSTs0c+bzhyhdH 11eh3WQETYNg8NKGlGmucBkw1ADhq1kQc08Ug4AvHPiwArrINQjJd1FGJzTiMTD3VnBQ 8cZqBshbJ1SF3Cwpg2AxseL4/+eI5BfVNzcaJm5hL5jofmFqtXfU2+POfMdMl5KBqRW5 XtYw== 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=mTMuhlIRWVoEZltI4+2YaDwh5XAg4sdY3qJkZhDTV564Tx/H/df9j049jmfCnjWmsJ viYvFHR7W8Ax0qPWeInRbpcR0NR/mRIr8QxfZ9pE9hSkK20OV2KPUlblL6phxxja1u3c m1kZOee2sFaHIJoQis3skcZpSTWn0MKI5CP1+9etyoTE2Sab3s2QbAjzCCZYiRFEU+KI JIEY9/aXql0SaLj24fpTUvYRIOwatMHq+hrizk2fZt1/nslZ9meOx2zSzcdzWSDfWcd9 Vae4+xIwWUcVNJEzk8xzR7UB11ZSzjqdl4SfeevQz7jnXMAS96EM9jzwbqbj5HxKQ/t9 mz+Q== X-Forwarded-Encrypted: i=1; AJvYcCXonagH/5sTaxwLVMHy3ZyWkHQGsVDkSrAyZa0+tY58el4la0Z4qj4nCvA5KaNOh3xuELe18PLmLM96b0Tbzl7CfZDIYih7AKjAdR1tww4= X-Gm-Message-State: AOJu0YwPlEaPuJ91Mu65byYzx3gpQMV+Z1mc4YkS86kRDO1MkHkzl0jV au2EItUCGriWGj7qobxRMvMlQ0avXfy91Fpl7N7Q9iCbYjhdv1h6 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) 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 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: 13649628 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 6EBAFC41513 for ; Tue, 30 Apr 2024 16:50:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.715055.1116521 (Exim 4.92) (envelope-from ) id 1s1qgW-0004bN-8F; Tue, 30 Apr 2024 16:50:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 715055.1116521; Tue, 30 Apr 2024 16:50:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgW-0004YJ-1C; Tue, 30 Apr 2024 16:50:28 +0000 Received: by outflank-mailman (input) for mailman id 715055; Tue, 30 Apr 2024 16:50:27 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgV-0003oO-1H for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 16:50:27 +0000 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [2a00:1450:4864:20::132]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id be96d88a-0711-11ef-909b-e314d9c70b13; Tue, 30 Apr 2024 18:50:26 +0200 (CEST) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-5196fe87775so6618119e87.3 for ; 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) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: be96d88a-0711-11ef-909b-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495826; x=1715100626; darn=lists.xenproject.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=SV0KzIh0CZMuRJRNmROrp7uDRNRHphfeW6alYywSBbSBtIt+2iooagzErGW7R2F9lF 1419QQJGPVHm0kh34cyb12zdGVPRblEE5sEO0bOZdkYiXnlBa3x/ZXyIs+O9F/txoRe/ FDISxM4Nsd4fYSi4zn75y1kHAyyQkQ2fBTyLFx6Ci4q4LaeD9kwpexuSpdUy8VAuF27p ZozmHzxrHC0VlrLFU2YX3DcPdxDoDmtZM69bsDGf3QAWwZSKfvnh4A6aNhdoVQh0dRF0 gvUozpfM12xogzixpWcxnGnmu8ENC1ifqHnrCUhRWjIczuu6Wv152w9xj9LumGF5/ZA2 k3CA== 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=Mo3GS0r8Ulw24Fk9tK/IIRfOmH4H1PF0FckLKexzsEru3Yi/xVl5NknQGn3bFTYAe1 2dvFWGv1cc8PENZxUI976uffhKADH3iX9qOFaew1m2xM7r1tKrdQ/Qc+pPd8iFmhm2Gi /lCUnDteH9KTRAW2fZ6iNUn5rvV5eNaJb4G0nwxMUpRusICdrCGa9mh3LKvX2KygzAX4 9xTZXz5piCebs7ohLUATFHddmIfUC/Y359zEql56wJVN7JGbHGG6fAQgNnCH34voxhAw 95syM1/wjnmuc18X6HbYaBiHxUBGOEwBbbL8W7fpzfsEVPupzKQGTiKY9PfqbUXNow4u woIA== X-Forwarded-Encrypted: i=1; AJvYcCXyFRgonfsffjeN2LOt3+PSzYT1q0krF+SWcqFniy/eywiqXRTHCd/v1unUGsbibdcmOQHcGrjUyliT3QPck0o0GS76TVcRZkmK/ZeqizI= X-Gm-Message-State: AOJu0YzSF631bGVMM2yoYj0usUXSRdw0voBv/wKNiNtGk8Ih1pwDDSbO jpssq4DFfHCKUN38bcWP+UOe/jcOvdakfEGhLp+k6iJddZVMvKlYVD7n5UKX 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) 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 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: 13649632 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 6BE50C4345F for ; Tue, 30 Apr 2024 16:50:39 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.715058.1116564 (Exim 4.92) (envelope-from ) id 1s1qgZ-0005or-Vh; Tue, 30 Apr 2024 16:50:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 715058.1116564; Tue, 30 Apr 2024 16:50:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgZ-0005nD-NB; Tue, 30 Apr 2024 16:50:31 +0000 Received: by outflank-mailman (input) for mailman id 715058; Tue, 30 Apr 2024 16:50:30 +0000 Received: from [94.247.172.50] (helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgX-0003oL-T1 for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 16:50:29 +0000 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [2a00:1450:4864:20::12a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id bf83db4e-0711-11ef-b4bb-af5377834399; Tue, 30 Apr 2024 18:50:28 +0200 (CEST) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-51e75e7a276so742448e87.0 for ; Tue, 30 Apr 2024 09:50:28 -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) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: bf83db4e-0711-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495828; x=1715100628; darn=lists.xenproject.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=Cr6rYcX+49Pwp/ZaOyNGmqouxkYQodnwJ/cfXmF9ZWSfJZKppkCA1LocdpRlwvMMp4 1YuvD3f+33RNq5fY4OSwa6KEIVo0N6xc4z6/8pF9p8dX66rso7omjrTcBMlYW4kveQIu 7LqaUAoLrQItScK4j76bP8y6Q8YN56JJP6lO+PniIfT0doTDyk3V+v++Xjni8bx0a8lk NklPxwfRBfeJ54SJbR2NRWrL1ckHwDhhjmPlIbn7PJek3XCTMb0k6S3Dp6ro+3EfiuVB 7rO32N4Ma5BE3UiaqMnOlmTRwXI538wftbwC8+TYIJ6dtzvaHaNbrsZ53OkESwG6HiXt omfA== 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=ls47+iDTyr+tnxjwy+JtBt09DW3lBWIjIffeYjxC4iIYh5s0agJb9CySSY7mSyzmck jgB8uE+f+5E8UT1XguMoAq/t0gJMTjZSAO3pHefajXazw1S0d0Ix7wTGnSZmZajqVmvQ Sb/ThhXUDDM/cdJTnN1yXpU7GeHHyycL2/aYJjZQeRDMZ42puYs5O4u1LrhkPgtq2msB f18GdH9w9gAiyMUkkpbStoOTFDre1XD9hNICldfJlPtUGiWPbmlzAgRnO0UFupSc3wgx iq8QC6FK0ZQipFmuQ0Vqn1PGj7ggNgMvv4MAL8CVZev1Js3u38cv8FirGfKwYyeOt+Rb 4ohg== X-Forwarded-Encrypted: i=1; AJvYcCVWAUMKcSVQTdkm2sERhxIM6/7mPU4gtGuGuhv5gjyyLESEQfKQQEPHP2/a6tMF2e+lNDcJ2I1bmN7dFNC3wial0ScrCoXGqZpQyb0VaRo= X-Gm-Message-State: AOJu0Yz6JPJN4kzjLql8HNXxYKzC5KgNGYsrcnm1zwsRpLfuSuhk3yln LaXrQ0H0inqbhuY+YpVExnS1+ma6XtjNyqrWNmU6p98iNXehepWC 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) 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 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: 13649633 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 48676C10F16 for ; Tue, 30 Apr 2024 16:50:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.715059.1116570 (Exim 4.92) (envelope-from ) id 1s1qga-0005ta-E4; Tue, 30 Apr 2024 16:50:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 715059.1116570; Tue, 30 Apr 2024 16:50:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qga-0005s4-3j; Tue, 30 Apr 2024 16:50:32 +0000 Received: by outflank-mailman (input) for mailman id 715059; Tue, 30 Apr 2024 16:50:30 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgY-0003oO-HV for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 16:50:30 +0000 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [2a00:1450:4864:20::12f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c09fff96-0711-11ef-909b-e314d9c70b13; Tue, 30 Apr 2024 18:50:30 +0200 (CEST) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-51abf1a9332so8147574e87.3 for ; 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) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c09fff96-0711-11ef-909b-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495829; x=1715100629; darn=lists.xenproject.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=C2ivup4o//cBdC0zkrZ3XXD7eLhRaWvna2M7qn+FbQbxbfkiwIdCx5b5EhYAyETeci L4aW9FDbx9nRL9aG7Ydwjf2Bto40nYF8sCDMotzvwPtiv3gGBC/uVlDMvB8nTP8kIZ2j RvHwZVO83lbmk2BJaj+P3aMKL/0PWeof8o6HMLc+jfHl16B4xYwG7D69rNoP4BDp30xk hvhi9MsXY0ZAuHRkxtAUZnElXJedw+L3CTZrVrXsLrmounO8i42cLrky5oDKjmBI6/rU /DsYd5bJ/z5kB9xANALIFcmGikKSMz/nIzav1yt6+xBF3JLzbXm2XFp5blvXGK0TrOE+ uYwg== 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=tHzMrGm19oC08Mp0nc/+2jYiPYSp1+5MrHJ5HFGt1OK0JnEGAH/eAvdTKMtWOPUKEu ueSsL4kQYqswtNc+nKdmeeT6oXqkI2et8CMiAjaurVRAxLSKtmoc4wPX8CIMzmUcDEfZ 3kdqnCIJGSiQaPF6Ak8Fj7SQ/GkEAAUfo3TzT4CAjeyi3irhhWX2lESYSo04z2NWzami LI2EFOmLMD+9Yk/Z14jyWq5XLWdpHomTw2bs91CcMTGIzLNVq9f/L86e1M6w8VVgvrYU jCti8n3ZaqTb3dprQaSg9uOm07bJ7+tiEkCWOMbxAQtt+mG7Y4ESqF1LmS3rAJMZ9TXz zcqw== X-Forwarded-Encrypted: i=1; AJvYcCWry9zVOoY5iJVZSjlkAfl3BkNptpESz8di2ejcIZBQizccWpTNO24IARTNyD7wnvQLJVm/UYeQPD4UOje2Q1V8h6B6FkAFGp1zt+azDNE= X-Gm-Message-State: AOJu0Ywf53XOQhQWoNgDwk4MF9Ulk3SAfyGHs+fKluxW0XWtssg/+Gkc dKlgdLYmoD8XxnD1KdwHny5Hv15/CPGX8ZrYjKyEhCcBDfsiBSY4 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) 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 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: 13649634 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 B8E55C4345F for ; Tue, 30 Apr 2024 16:50:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.715060.1116585 (Exim 4.92) (envelope-from ) id 1s1qgc-0006TH-NR; Tue, 30 Apr 2024 16:50:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 715060.1116585; Tue, 30 Apr 2024 16:50:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgc-0006Sw-IC; Tue, 30 Apr 2024 16:50:34 +0000 Received: by outflank-mailman (input) for mailman id 715060; Tue, 30 Apr 2024 16:50:32 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qga-0003oO-HV for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 16:50:32 +0000 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [2a00:1450:4864:20::129]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c1d82d28-0711-11ef-909b-e314d9c70b13; Tue, 30 Apr 2024 18:50:32 +0200 (CEST) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-51e75e7a276so742549e87.0 for ; Tue, 30 Apr 2024 09:50:32 -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) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c1d82d28-0711-11ef-909b-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495831; x=1715100631; darn=lists.xenproject.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=g1BNyP8zbtW4VjqKQWjhlbRFloMwYhZZpHk75tSbpABpR+XMihQ3sQHthIOThNUKj+ Gzo/uaiBZDUe+r02UmqpIuqVb2QqrlhUMqU4W8SUNQc5KhPmBLasgbR3zsPe51/yfeJ9 QI7g7gzNFb1QEgQWX1ZMzxDwX8gDlY6fooRlM/+2Kg71oS3pPUBfxcDqi4YSbyWAoEtO AS3NYzEV/VMDpDECgxEdofyVaQodeDDe96jmN6iZLVctSTGZMLEjtq03WoYDUFUZ90eD fcyJ2pR46p8KSOSi3B6vW2mZPBUl9OkcXzPKAQhMnmzZrAoP82SDjsAGgTnSjpdBkdne LWXg== 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=dLALQPZQF4kX99rZzH8O3QbMHHh6U40Qsvo7YUWUhEHYV8E0LmndIapwGh69VK2xax eT9dNYX3MtBR1YnI+p6BVvN/gMbjUZ/Yj0Pb03Q0gAPEfvMh/BKoqWPmYqaCOL+OFYIH wsy2CIoa/JQOq6OSt2SjGizk9m0npmKrKbtYwrCA90QHV+4iH3H4x5PjRG4u1PPbxL2O cwCZQf++7+QEKU9i3HiLoBYE3gjyZhwS2W6I2z8zZKIM61ahj/sKllXUgf5H+MZEJBWE RuAAockd7V3vCIrNsKNMOXWXHGADbnlhhEULI/0jJ14B+qGqVjJJcUdBGarfvFZZi/Ow okow== X-Forwarded-Encrypted: i=1; AJvYcCW7OuotFrzUMEykrw9+1UskRhqn3qm4/yDNydvcWxbfwwn8j777dJPyP4sLENwG01R1IF7xCq2mjbtNiicDJRO4WS1V+9Ed4lHVLSpEjTA= X-Gm-Message-State: AOJu0Yz+hpj5rD2CSdaql1kWYMB/dXLLieQm2d0wk/lKosKc+S6ShMd3 moD/FKlan0k5WOcR7kPxGMYWTOq2CNJXobcO6THCk9IJ4Lrg83W5 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) 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 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: 13649635 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 34734C4345F for ; Tue, 30 Apr 2024 16:50:46 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.715061.1116595 (Exim 4.92) (envelope-from ) id 1s1qgf-0006r2-3F; Tue, 30 Apr 2024 16:50:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 715061.1116595; Tue, 30 Apr 2024 16:50:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qge-0006qR-Rt; Tue, 30 Apr 2024 16:50:36 +0000 Received: by outflank-mailman (input) for mailman id 715061; Tue, 30 Apr 2024 16:50:35 +0000 Received: from [94.247.172.50] (helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgd-0003oL-4A for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 16:50:35 +0000 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [2a00:1450:4864:20::129]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c2bdc16b-0711-11ef-b4bb-af5377834399; Tue, 30 Apr 2024 18:50:33 +0200 (CEST) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-51ca95db667so5702717e87.0 for ; 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) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c2bdc16b-0711-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495833; x=1715100633; darn=lists.xenproject.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=icEAr3fJlsY3SDSaakoAm+1KtPRerKSExKsinllkHYcrmX60zXseeGtyHOQLsP7Ejl aTEhSoBh+jff1fevOs6KiNB6/wCYCxtQxKez8s5RIDBFie3pYBLq2gWJIuH6NYW+YmE9 mij1d5Lc/9zm5RDTrDXYfkzjUNW2Z32XN7S7Tfg5023pcF4hlevg9cBJyw/zzKJKZqPj +eRxaJCgsKtU/c/OyO39j9nTDOWvlwIZnPMW756jFpy8S3hsNNJLZtbOKgX2cPcuI2j1 LhvrVvXiKcTmYGJPnOT+UHbPDUIUpTuhizS46k3lpJg4+BlSd4jhYIJ5fioMUTDxQH57 hJZA== 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=PoQw33cqBMZ7y5V1QxJnSeA1BuT305q3oxde2Wu6CT/WcJY22y7EqxXZLItuqSnHnD 0PKk1kQFRKba4Ed9YNx3k/AVwm6ZGVtXRVZUE+epZm4motNt0iGsStpM3R2+TnevOpBk pDvPpNHejG2XyFIN3pe0rDIIyJW5LO1aR85XkNNGgx+mgXxDKplv9DVL5w6v3OQvu63u GFW2WRTyCoh8lJ7A1WUuWxUwtCteFRR954Gl7zal2bznAM1dVY43ZV8N4Wh8e1o9px8I +zy+fGqow+UivgZ9ttloJwA8Dpxewj4tfxZ7KHxVYXwqM5wZCwKg5RypB6Jc8+RFpFVB 4h3g== X-Forwarded-Encrypted: i=1; AJvYcCWivmB0f4d4SFx7uBIkhF7rBXerWR5aDxd9AsB9520qecJ9QFYUTPP56rpYM5HlfJkw+DH1Ed3lmhFKs4nGIZMSICxivS6tCYM2spUMKig= X-Gm-Message-State: AOJu0YyfsvJlD0/zMRB9tljvtvcSlAGUN5BSj8Tefpe7l0dWKgmd1C67 ofnXQbbcPvMVKBybrdBTsMWDDJKPzg7rwIY82U3SUqZ7pd4Id04q 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) 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 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: 13649636 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 59DA1C19F4F for ; Tue, 30 Apr 2024 16:50:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.715062.1116603 (Exim 4.92) (envelope-from ) id 1s1qgh-0007CE-06; Tue, 30 Apr 2024 16:50:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 715062.1116603; Tue, 30 Apr 2024 16:50:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgg-0007B0-Nn; Tue, 30 Apr 2024 16:50:38 +0000 Received: by outflank-mailman (input) for mailman id 715062; Tue, 30 Apr 2024 16:50:37 +0000 Received: from [94.247.172.50] (helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qge-0003oL-Ti for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 16:50:36 +0000 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [2a00:1450:4864:20::22a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c3d5505c-0711-11ef-b4bb-af5377834399; Tue, 30 Apr 2024 18:50:35 +0200 (CEST) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2e0a2870bceso29624661fa.2 for ; Tue, 30 Apr 2024 09:50:35 -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) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c3d5505c-0711-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495835; x=1715100635; darn=lists.xenproject.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=LybbEw0JirCXoCzReIPkFdeH6EfZywYm+TjP6g8JbBmpCJBXzJGZDGGqbEkIB5DNuZ vcS/rHlWlYCRwbVO2mgyxYgLkjSLMK/feIFWJIRFT3GNvgSLM2YMV6yUUuGQ8/Obby5y n2utJ432kJcxWSyARAhZG1I4/6YicaBH5WmYqz8WJZFaKJ/aNRfWPUzvEo1czzKkCGC3 F3qMjnHCom4F41QiqUKHkHupgoCvzNlNBFMVCi1Ty6HSFtQvnvKBDI90XlNFWS4zUL74 6sWtrDAf/TLw+ucnRAJF2XK2RO1R83qgDHh8liEPMMeeuhTON2XPhF3ObZX5xs9KSp2H FprA== 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=fCNgQThFMv4nr8xAaPv47NVeO6SxM+OEfQqVSJdbYVFotQS+egerZXKyRLpF1/4Xtl k6Q1wjRJDC3VIWkwUR9qNDWeJcBJ6oar6eMIu6LmHC21RKIPywYTHsOJ+3k3UIDaBme/ zVmZpCxOYyUGZigO1ndSh/GqsfhGatHWdEmu86CR3kDP068/wLaa1N+ZztfIKwfYQDwK nlWWZ/QNrRTdmkDfjYPdfS+mVwdGkFUmZU1aOnh6eXlaTY+bW2fywixLRt+bZKZHgTUI WFqaQfVj9GI42Peo2RPp1MBaTxgKQah6T8G/5vEEKTJKViu3jGhKp6TYr8P80WfyxkWK N/vQ== X-Forwarded-Encrypted: i=1; AJvYcCXTK0Ch2r6kYSAzppN5i/tv8A7Xa2UHuDJIWAGlTygUhXL5A/DR8rfQz/LS6Na87zz6f5qPBBlHa0FMT2U4vNlGoa3hmZ1eNM9Nf4Vv9I0= X-Gm-Message-State: AOJu0YyCtt5d3rTx63TlbO0YMljBfnlXjHi/31/KRU7bjazDAkVzGcsc IbFKQUtr19S8bpyRGit0wQ+159C8q2E0fUvdqBak6mp4UyD9tWWktaN98fIa 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) 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 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: 13649637 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 ABA4CC25B10 for ; Tue, 30 Apr 2024 16:50:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.715063.1116614 (Exim 4.92) (envelope-from ) id 1s1qgi-0007Y1-Io; Tue, 30 Apr 2024 16:50:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 715063.1116614; Tue, 30 Apr 2024 16:50:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgi-0007Wo-AG; Tue, 30 Apr 2024 16:50:40 +0000 Received: by outflank-mailman (input) for mailman id 715063; Tue, 30 Apr 2024 16:50:38 +0000 Received: from [94.247.172.50] (helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgg-0003oL-JM for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 16:50:38 +0000 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [2a00:1450:4864:20::131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c4c4c297-0711-11ef-b4bb-af5377834399; Tue, 30 Apr 2024 18:50:37 +0200 (CEST) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-516d68d7a8bso5469247e87.1 for ; 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 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) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c4c4c297-0711-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495836; x=1715100636; darn=lists.xenproject.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=LMfGWXvxGMH/lkQExl6XjNof1EQ/88r/lQJJ9Uf8TX0QdRxbBdGMBftfuM3voPhI8D zlWFA0GCNQXx+6yWti9L+EXVU5Q12fIrl2gupYOyN3pUTN+rT+wLJGgZbRON+v850A7z aXZKYXJfWhGSzRN1O7Ef8SVqysUh5fvUe3Z3RsK+ajXhVKKEsiyIeY6Cz9swd8Zmcfr3 9cASj3hl5ujIU9qbHee7E9/ZXQHHN3QRGF0fN1tXFIwqG6n+KYwfH53D1XDnvIuAMWo2 YLhKeEWTupwNtW/W1eSBj+bxoviRt1XhLPs0b0uYk2q8IjmbCqFIjx6rXJ/DA6ixCEeb DnfA== 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=fM/rsQ4jg/XMchvgm/RbAIlLpSfRLIdVMB1/dlSDv7kqInN/GtWggqwN/d5Wl4k2kM mEpXqCezoRX34P6JE7Ja7o1+06M65OZ+aJ2GrAXFZD/8AvBn2CPu75xE66TGDysDe326 KfRwjl5aD1A3J4svcSFAEEax24nOEemPqeKpOy61rqkWzzZglpxtx3gVHZ+zXTq2R+md 9xSfk6Etl6MiaCsjtdDQ8/P3PoTuZal0foI6W7XhvS8KPGp+YHcdHc5HDyCncrow3BGd JkptzmXmokpWxhRN3Y28dJhtuQHdoAPn/8OveVFnEphI3RC0KT+++06hq+2UNeFjfKxb VcjQ== X-Forwarded-Encrypted: i=1; AJvYcCXppVESB1DGLCdCLO69BLl8U35b6xq8XiLLVvWmPDi+VOjmpO6rwOTj1fpWJrWpqsw8KlxHomJjrDemorlj/88wDwnZos9kQYqDTmXUOU8= X-Gm-Message-State: AOJu0YzYkgy+kdYlYy//wLsPwEOKmaK1XAQNADwxTJd9M1fHG/JymO+t IRzDHiNGMwLl3RShQ9XbiKtaddpF2tGz5uEfSlHU826elTnMQ1V+ 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) 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 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: 13649638 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 8B5CBC4345F for ; Tue, 30 Apr 2024 16:50:50 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.715064.1116623 (Exim 4.92) (envelope-from ) id 1s1qgk-0007sb-22; Tue, 30 Apr 2024 16:50:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 715064.1116623; Tue, 30 Apr 2024 16:50:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgj-0007sK-Rk; Tue, 30 Apr 2024 16:50:41 +0000 Received: by outflank-mailman (input) for mailman id 715064; Tue, 30 Apr 2024 16:50:40 +0000 Received: from [94.247.172.50] (helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s1qgi-0003oL-CD for xen-devel@lists.xenproject.org; Tue, 30 Apr 2024 16:50:40 +0000 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [2a00:1450:4864:20::135]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c5b60bf3-0711-11ef-b4bb-af5377834399; Tue, 30 Apr 2024 18:50:38 +0200 (CEST) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-516d3a470d5so7412437e87.3 for ; Tue, 30 Apr 2024 09:50:38 -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) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c5b60bf3-0711-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714495838; x=1715100638; darn=lists.xenproject.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=N5h5g70aqBgWKz4Hmt7M/opgKLkbSHwPm7ElDn41hvoHkYob1tkmbQjoGQCM43hoIf Dwn2x6nnn2qXqmW3ryaLC+nqGBmXCCDBKzWjMacHCbjrZ3Lun8eNuGfY3kVfHxVkEKQT kPw7gDWPi0TD6gHAWWUs0tyTXBZGcRrLnzQVxvAscKdhI7/TIbLY/fCF1iDKW2g0tnD+ IyZ10eIZHVCwT6563HcekPa3quHJDoBlNLiLPW8FcNi/zVJyqWztpaaUJcBMoMKa2uRo Wfi5FAIPs2d3lI+oAFXup1jafobxVfLt5K4V6rqkYaONCWsfDZ6u/KP/ogVk9kbrLYiL qAvQ== 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=D27WMBHTjy4q3TB/n4WosluvrIe2rfUkj9pEabrk/8kQzEKxYt3/mPRttmEv2E86i2 BAFmvlmybE9yDLfVDoSZD3bo6YElCPbLY9GIvTilhY3JdmNuv3+cBu/TH6g18BKn7g4U /eVRlkQlDObbh30zLGOfBL8ri7BpdOUvCMvbtc9ZsjUO6U4YXz7hkv16Em3ByCtRp5R6 Ymrm35IjrIwkIQhW7BTaamzlG8zpEcCOcgJyozCuDT5pUTS+bh4XgvZ3RSsozYif8YuT bvwUvnqdea6cSrR76pSOZz9mjaIDW/99DkDavghjffZ+UWAdh9OVDBltvBgcGgP3c+3O H+ww== X-Forwarded-Encrypted: i=1; AJvYcCV0lW8UFz8ULHUIWrWehD2A0kJpD2GjfjhgSnOnQhFJv/bDolgc7BBn0T1MltyHj+B8haqwwQxN9IrmCtlGb6zS0IRNgcg3FZFnZ56cFlA= X-Gm-Message-State: AOJu0YwmA4+wz7uqr915XXI1MJdkgJgI6wz8u7anD/BatM7vL8l440Eg XdKuHO8jg7gb1ooR1TL1rFfXuwuigKwzjsrC+2qyDz/mdE52vAGk 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) 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 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