From nobody Fri Nov 22 21:01:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725969717; cv=none; d=zohomail.com; s=zohoarc; b=FbCxfkHWCXYy9QDtgypHOAmxguS57agVtZF9nLwID+3JialbRDn6wOSytv9/WfMbGFqeEmlguhvpvVYAK+L73lTHnUvCY2kElVfSdWoAQOKkZrRrAbCNm7ovyyNMMqPiGWbSfxpGmyAoAFivFVZVcQzE2Qound9EiyLsyLF4T4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725969717; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mJ+nu4OBRWNA66awMDjqGlw+Jxra9J0zh8CjtX6F30A=; b=dsm7L3d1wd9h/sYsI26RzE+T4rvV11w6m44FR2TxqG6YPD+lWgoMHUqIIO0f0CrHfvE56pJMes7FzhqMbjlNLGPvdVZC0NTv4eKaLEiIijD3vfHs+G4t9U03alDttuq7szx7865B1U3dpFDDWllGNnm9pFYCPJAjVHeNagZj2+Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17259697170801.2834937415143486; Tue, 10 Sep 2024 05:01:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snzZ1-00048z-Kd; Tue, 10 Sep 2024 08:01:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1snzYk-00033t-Nl for qemu-devel@nongnu.org; Tue, 10 Sep 2024 08:01:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1snzYj-0008BH-1X for qemu-devel@nongnu.org; Tue, 10 Sep 2024 08:01:26 -0400 Received: from mail-oa1-f71.google.com (mail-oa1-f71.google.com [209.85.160.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-193-qsoj8XfGOLaU7bAnHvavwA-1; Tue, 10 Sep 2024 08:01:21 -0400 Received: by mail-oa1-f71.google.com with SMTP id 586e51a60fabf-277e6462843so6440022fac.1 for ; Tue, 10 Sep 2024 05:01:21 -0700 (PDT) Received: from localhost.localdomain ([115.96.78.44]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-7d8259bd054sm4722766a12.77.2024.09.10.05.01.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 05:01:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725969683; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=mJ+nu4OBRWNA66awMDjqGlw+Jxra9J0zh8CjtX6F30A=; b=eTkbe/vvUx+dnh6fSh34x3+VqwCBeegmyP8v/ahtE5jM+6fqQP9fB74UjOPq4BhuZlfzRO SBwSEtHleiHSxggqlu6DI/tY5oXDjvi9ZqKaQWUglxuCoZYYJQyBWGW7UNViVhvjD8KHF6 sv/XARygkeZuuPpG4apnbS6iRSzdk0E= X-MC-Unique: qsoj8XfGOLaU7bAnHvavwA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725969681; x=1726574481; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mJ+nu4OBRWNA66awMDjqGlw+Jxra9J0zh8CjtX6F30A=; b=aAEj5jjbvgF/o98wwwIzcSY4BF5b2R5EUoAvfvbOnFsE/uweYWKQcOL196aBrWEg4B PMdveO3kGJfrJ1fvzmCauL2d9pPk7wNhK59fZtxAtfTd/04tX8a3AVpc/4eSGVurowEE YRfeMAWsCME8jzrJZt8sLyLmkOoNtQQaiGa30QbV6JyWhxq3yNTOIdxkIFHZsVxzUjze 6/ztYEl4TxOZdTdrz5b04xKphmkP27XYKl+WcQ52qwgxiyEYftCqE/QZMGV0n2mqQXt/ IHVRkMWm780y9uzshI5uwHJocoEvzY43gtaY010rKAc77Y9KXzafFWUYGzFrZcfzlm5w jTgA== X-Forwarded-Encrypted: i=1; AJvYcCVSgErQPAhsDsbXsFsD1ce+uiD5bX4llWRZq3ir0WWsnLVof0GcoQUkuwNkCh0RTkk7A/F+a/KxyHl1@nongnu.org X-Gm-Message-State: AOJu0YySSQCrAb/YioCHtmqlAq38BPZYePRTjUaICwEt+YaETSEMrB4n abHUkRhF5IKnOQlwA9d9WSsS76LmIdwX36qlIxhwRp57x0NWo5IkMD1VzJqFFmfZtpp+hGXKdsL B3zxGlpQlLIHqbQriWUFHE5/wcskLKZXj/9+F6DzKsc4QxTNisp6V X-Received: by 2002:a05:6870:420b:b0:27b:71ec:1463 with SMTP id 586e51a60fabf-27b9d80424bmr6022327fac.14.1725969680768; Tue, 10 Sep 2024 05:01:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKNM1RIEOPmWgPTNkRCyIY9guWZduAmShOA8KD9AwMiHIEz69RwSIK+/aLznVnMpZVYwwnKw== X-Received: by 2002:a05:6870:420b:b0:27b:71ec:1463 with SMTP id 586e51a60fabf-27b9d80424bmr6022290fac.14.1725969680252; Tue, 10 Sep 2024 05:01:20 -0700 (PDT) From: Ani Sinha To: Paolo Bonzini , Peter Xu , David Hildenbrand , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: Ani Sinha , qemu-devel@nongnu.org Subject: [PATCH v2] memory: notify hypervisor of all eventfds during listener (de)registration Date: Tue, 10 Sep 2024 17:31:00 +0530 Message-ID: <20240910120100.9460-1-anisinha@redhat.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=anisinha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1725969718093116600 Content-Type: text/plain; charset="utf-8" When a new listener for an address space is registered, the hypervisor must= be informed of all existing eventfds for that address space by calling eventfd_add() for that listener. Similarly, when a listener is de-registered from an address space, the hypervisor must be informed of all existing even= tfds for that address space with a call to eventfd_del(). Same is also true for coalesced io. Send coalesced io add/del listener notifications if any flatrage for the address space registered with the listener intersects with any coalesced io range. Suggested-by: Paolo Bonzini Signed-off-by: Ani Sinha --- system/memory.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) changelog: v2: tags added, indentation fixed, commit log fixed, code cleanup. diff --git a/system/memory.c b/system/memory.c index 5e6eb459d5..8379e086fb 100644 --- a/system/memory.c +++ b/system/memory.c @@ -941,6 +941,38 @@ static void flat_range_coalesced_io_add(FlatRange *fr,= AddressSpace *as) } } =20 +static void +flat_range_coalesced_io_notify_listener_add_del(FlatRange *fr, + MemoryRegionSection *mrs, + MemoryListener *listener, + AddressSpace *as, bool add) +{ + CoalescedMemoryRange *cmr; + MemoryRegion *mr =3D fr->mr; + AddrRange tmp; + + QTAILQ_FOREACH(cmr, &mr->coalesced, link) { + tmp =3D addrrange_shift(cmr->addr, + int128_sub(fr->addr.start, + int128_make64(fr->offset_in_regio= n))); + + if (!addrrange_intersects(tmp, fr->addr)) { + return; + } + tmp =3D addrrange_intersection(tmp, fr->addr); + + if (add) { + listener->coalesced_io_add(listener, mrs, + int128_get64(tmp.start), + int128_get64(tmp.size)); + } else { + listener->coalesced_io_del(listener, mrs, + int128_get64(tmp.start), + int128_get64(tmp.size)); + } + } +} + static void address_space_update_topology_pass(AddressSpace *as, const FlatView *old_view, const FlatView *new_view, @@ -3015,8 +3047,10 @@ void memory_global_dirty_log_stop(unsigned int flags) static void listener_add_address_space(MemoryListener *listener, AddressSpace *as) { + unsigned i; FlatView *view; FlatRange *fr; + MemoryRegionIoeventfd *fd; =20 if (listener->begin) { listener->begin(listener); @@ -3041,10 +3075,31 @@ static void listener_add_address_space(MemoryListen= er *listener, if (listener->region_add) { listener->region_add(listener, §ion); } + + /* send coalesced io add notifications */ + flat_range_coalesced_io_notify_listener_add_del(fr, §ion, + listener, as, true= ); + if (fr->dirty_log_mask && listener->log_start) { listener->log_start(listener, §ion, 0, fr->dirty_log_mask); } } + + /* + * register all eventfds for this address space for the newly register= ed + * listener. + */ + for (i =3D 0; i < as->ioeventfd_nb; i++) { + fd =3D &as->ioeventfds[i]; + MemoryRegionSection section =3D (MemoryRegionSection) { + .fv =3D address_space_to_flatview(as), + .offset_within_address_space =3D int128_get64(fd->addr.start), + .size =3D fd->addr.size, + }; + listener->eventfd_add(listener, §ion, + fd->match_data, fd->data, fd->e); + } + if (listener->commit) { listener->commit(listener); } @@ -3054,8 +3109,10 @@ static void listener_add_address_space(MemoryListene= r *listener, static void listener_del_address_space(MemoryListener *listener, AddressSpace *as) { + unsigned i; FlatView *view; FlatRange *fr; + MemoryRegionIoeventfd *fd; =20 if (listener->begin) { listener->begin(listener); @@ -3067,10 +3124,30 @@ static void listener_del_address_space(MemoryListen= er *listener, if (fr->dirty_log_mask && listener->log_stop) { listener->log_stop(listener, §ion, fr->dirty_log_mask, 0); } + + /* send coalesced io del notifications */ + flat_range_coalesced_io_notify_listener_add_del(fr, §ion, + listener, as, fals= e); if (listener->region_del) { listener->region_del(listener, §ion); } } + + /* + * de-register all eventfds for this address space for the current + * listener. + */ + for (i =3D 0; i < as->ioeventfd_nb; i++) { + fd =3D &as->ioeventfds[i]; + MemoryRegionSection section =3D (MemoryRegionSection) { + .fv =3D address_space_to_flatview(as), + .offset_within_address_space =3D int128_get64(fd->addr.start), + .size =3D fd->addr.size, + }; + listener->eventfd_del(listener, §ion, + fd->match_data, fd->data, fd->e); + } + if (listener->commit) { listener->commit(listener); } --=20 2.42.0