[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 5/6] tools/oxenstored: Rework Domain evtchn handling to use port_pair


  • To: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • From: Edwin Torok <edvin.torok@xxxxxxxxxx>
  • Date: Thu, 1 Dec 2022 15:22:33 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TatEI5b8263TgZ3IJUXoVjUTdmc3FB2dmBSpE34JqNU=; b=oReEpoXrF9NHhQD/BnsWBeLPmvBZRRG1rVjXTJVLodsk2lHQIcth+U8189EKgJNnhutZwlZg33dpHs46QaqWrxmxvHz/WW+sd6h0JFi1nE3GyWTlbBpw96gky0Zho2ur3uYlF7d3XuDzVs3+KJ0xlvW1I3jjE4H5qxp2VwzPPNK3T+rQPNwa8oe8d0tPKvX2byaoFoWPGgi1iuZuTr4jA/WSiDwLxRhwQDC6EB16yISaGvWUNbhYAjlpBn8EbEJtqTXHR7lFsbXIk/Dn2rMW4QZ895v3qraqnG8IaEz4x+I/T/HoU1EucdkYchL7uSV8J/8b8QZfUtWiGZZDuZLfxg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j7jxA0sxyh4moKUTCR99onNPLDKR4/IOdr4pUI6NfhII/BMhg69NIv27AAk6lb8s40nCqeAeGaX6nIEPSp0HeSYqUowym1h9l8ZdBbF0O5hBbRXsVx3bxxuiTgKbEJ4CjWtG/oNO/jApZIlW4+vj8hJ7odEEq/tgdpVdeRk6zwYD82pmtDKJDHRbHF+WZwk+imYOqKnsTEuJxnNsEkk3uYHk0sn+TiuuK6t0R/9uPoVnKu6LAXtGNEjG808xD51BBW5FDHqS6C2h7Gmx3Iu/JxWiba7qpOO3kmQCL6t6HXSg2XTaHiSjvVGEElalrXAyJ2tOdyNYJkwq0cb6cC0+YA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Christian Lindig <christian.lindig@xxxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, Rob Hoes <Rob.Hoes@xxxxxxxxxx>
  • Delivery-date: Thu, 01 Dec 2022 15:22:48 +0000
  • Ironport-data: A9a23:q/83IqMlXbMbanTvrR22lsFynXyQoLVcMsEvi/4bfWQNrUongWcHm zFJXm2OOq3cNGD3LY0jYNnj9hlS68fdm9RiHQto+SlhQUwRpJueD7x1DKtS0wC6dZSfER09v 63yTvGacajYm1eF/k/F3oDJ9CU6jufQA+KmU4YoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGj9SuvzrRC9H5qyo4mpC5gVmP5ingXeF/5UrJMNHTU2OByOQrrl8RoaSW +vFxbelyWLVlz9F5gSNy+uTnuUiG9Y+DCDW4pZkc/HKbitq/0Te5p0TJvsEAXq7vh3S9zxHJ HehgrTrIeshFvWkdO3wyHC0GQkmVUFN0OevzXRSLaV/ZqAJGpfh66wGMa04AWEX0sMrWn8Ny tk4FAgmNAiEh72byrOwUNA506zPLOGzVG8ekldJ6GiASNoDH9XESaiM4sJE1jAtgMwIBezZe 8cSdTtoalLHfgFLPVAUTpk5mY9EhFGmK2Ee9A3T+PVxujePpOBy+OGF3N79d9CURMMTgkGCo WHu9GXlGBAKcteYzFJp91r81rGXwn6nCer+EpWV6OZUx1+59lYuNwI1V2GfjPCY11GXDoc3x 0s8v3BGQbIJ3FymSJzxUgO1pFaAvwUAQJxAHusi8gaPx6HIpQGDCQAsQjdfZfQ8ucQxRDhs0 UWG9+4FHhRqubyRDH6YqLGdqGrrPTBPdDBeIygZUQEC/t/v5pkpiQ7CRcpiF6jzicDpHTb3w HaBqy1Wa6gvsPPnHp6TpTjv6w9AbLCTJuLpzm07hl6Y0z4=
  • Ironport-hdrordr: A9a23:Ih4jo6jPL1KET/qVzBYFCcjh+HBQXrkji2hC6mlwRA09TyX4ra CTdZEgviMc5wx9ZJhNo7q90cq7IE80i6Qb3WB5B97LYOCMggeVxe9Zg7ff/w==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHZBNyG3A7uJdJD7k6750yETnX6R65Y7uIAgAAoLICAABCkgA==
  • Thread-topic: [PATCH v2 5/6] tools/oxenstored: Rework Domain evtchn handling to use port_pair


> On 1 Dec 2022, at 14:22, Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx> wrote:
> 
> On 01/12/2022 11:59, Christian Lindig wrote:
>>> On 30 Nov 2022, at 16:54, Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx> wrote:
>>> 
>>> Inter-domain event channels are always a pair of local and remote ports.
>>> Right now the handling is asymmetric, caused by the fact that the evtchn is
>>> bound after the associated Domain object is constructed.
>>> 
>>> First, move binding of the event channel into the Domain.make() constructor.
>>> This means the local port no longer needs to be an option.  It also removes
>>> the final callers of Domain.bind_interdomain.
>>> 
>>> Next, introduce a new port_pair type to encapsulate the fact that these two
>>> should be updated together, and replace the previous port and remote_port
>>> fields.  This refactoring also changes the Domain.get_port interface 
>>> (removing
>>> an option) so take the opportunity to name it get_local_port instead.
>>> 
>>> Also, this fixes a use-after-free risk with Domain.close.  Once the evtchn 
>>> has
>>> been unbound, the same local port number can be reused for a different
>>> purpose, so explicitly invalidate the ports to prevent their accidental 
>>> misuse
>>> in the future.
>>> 
>>> This also cleans up some of the debugging, to always print a port pair.
>>> 
>>> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
>>> ---
>>> CC: Christian Lindig <christian.lindig@xxxxxxxxxx>
>>> CC: David Scott <dave@xxxxxxxxxx>
>>> CC: Edwin Torok <edvin.torok@xxxxxxxxxx>
>>> CC: Rob Hoes <Rob.Hoes@xxxxxxxxxx>
>> Acked-by: Christian Lindig <christian.lindig@xxxxxxxxxx>
> 
> Thanks.
> 
>> 
>>> v2:
>>> * New
>>> ---
>>> tools/ocaml/xenstored/connections.ml |  9 +----
>>> tools/ocaml/xenstored/domain.ml      | 75 
>>> ++++++++++++++++++------------------
>>> tools/ocaml/xenstored/domains.ml     |  2 -
>>> 3 files changed, 39 insertions(+), 47 deletions(-)
>>> 
>>> diff --git a/tools/ocaml/xenstored/connections.ml 
>>> b/tools/ocaml/xenstored/connections.ml
>>> index 7d68c583b43a..a80ae0bed2ce 100644
>>> --- a/tools/ocaml/xenstored/connections.ml
>>> +++ b/tools/ocaml/xenstored/connections.ml
>>> @@ -48,9 +48,7 @@ let add_domain cons dom =
>>> let xbcon = Xenbus.Xb.open_mmap ~capacity (Domain.get_interface dom) (fun 
>>> () -> Domain.notify dom) in
>>> let con = Connection.create xbcon (Some dom) in
>>> Hashtbl.add cons.domains (Domain.get_id dom) con;
>>> - match Domain.get_port dom with
>>> - | Some p -> Hashtbl.add cons.ports p con;
>>> - | None -> ()
>>> + Hashtbl.add cons.ports (Domain.get_local_port dom) con
>> I would prefer Hashtbl.replace. Hashtbl.add shadows an existing binding 
>> which becomes visible again after Hashtabl.remove. When we are sure that we 
>> only have one binding per key, we should use replace instead of add.
> 
> That's surprising behaviour.  Presumably the add->replace suggestion
> applies the other hashtable here (cons.domains)?  And possibly elsewhere
> too.


Yes:
* Hashtbl.add -> Hashtbl.replace
* Hashtbl.clear -> Hashtbl.reset

Using anything on the left is almost always an indication of a subtle bug (e.g. 
Hashtbl.clear won't release the memory used by the buckets, and the only time 
that is useful is if you'd immediately fill the hashtable with lots of elements 
again, really code should always use Hashtbl.reset but that only got introduced 
in OCaml 4.0.0, so older code won't have it).

And the use of Hashtbl.add can lead to "space leaks" (eventually OOM) unless 
one really knows what they are doing (i.e. there are only a finite number of 
add calls ever).

In XAPI we have a "quality gate" that counts the number of problematic 
functions/etc, and makes it a hard build time failure if any new usages are 
introduced (and we strive to reduce that to 0).
I don't think these 2 Hashtbl calls are there yet, but they probably should be.

Best regards,
--Edwin




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.