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

Re: [PATCH 09/18] xen/xenbus: add xenbus_setup_ring() service function


  • To: Juergen Gross <jgross@xxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx
  • From: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
  • Date: Wed, 20 Apr 2022 14:44:31 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.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=mIgCx3qy+wGt5g+bKCz+mXdTduGa4CCdQN2W26eK25Q=; b=oXtOT8ju9HtXXNg+1j1HMHgm1d06Q//VtqwCT9wREK7HH3Qx58Tehj6KtVTtygk5GgqHpBM/ZNDck64vmRegjIAILXEtpmty3WohgsQ084RKaOIh0PN8CekFQ+5PVcbZGgG7LOliDJFoYZK5l5PHz/U51Dna6aZipYlUlMyXRF5veoNhZG5stqbKy7W6p7mLoe9154brMaFzlAgAYb9hgEBbspUkQY9iVeqhfcLKd0J+ZQOvhqIwcXySQS/rfwaOLbJ7/ZrM8YKTAwLMU8hzyfT4ySi1M7Pf+jR+58/0YcyumTfkTSr0buU8cM/0/mroPFvQBngOEZBlXFz8Ip7Cbw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a+lasMn6Hf+orNcQ4FZjRThhQA8GP+2opoEvIAbh4gEX3E79iL7qEnGgEenNH4mc2VafaNn8KPbR8qZjyXYYYN28ypwXZRr4lfkaVurO7m/sSmIeQ6R7yaACn7LXAvo+2KIzKGGo6G4/4w7GwW4OX5tyB5vYFcin7jHkIm2LAkFqVu7OK3frUkoD8RoSf+3dcVx0epW7gfE9TYv6Enb7lFTY4W64Rjw4UaiCOrv6Yh0udO5H3sRQl8aalaCQ/HucnaGt78FWqUMBdrfH/pmPJctn0y4cElaowldoaAEWgs51NkN0mzPWkQ38FwRTEq9DdaN65Uz7NEGBQZOo+uYY2w==
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Wed, 20 Apr 2022 18:45:06 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 4/20/22 11:09 AM, Juergen Gross wrote:
+/*
+ * xenbus_setup_ring
+ * @dev: xenbus device
+ * @vaddr: pointer to starting virtual address of the ring
+ * @nr_pages: number of pages to be granted
+ * @grefs: grant reference array to be filled in
+ *
+ * Allocate physically contiguous pages for a shared ring buffer and grant it
+ * to the peer of the given device. The ring buffer is initially filled with
+ * zeroes. The virtual address of the ring is stored at @vaddr and the
+ * grant references are stored in the @grefs array. In case of error @vaddr
+ * will be set to NULL and @grefs will be filled with INVALID_GRANT_REF.
+ */
+int xenbus_setup_ring(struct xenbus_device *dev, gfp_t gfp, void **vaddr,
+                     unsigned int nr_pages, grant_ref_t *grefs)
+{
+       unsigned long ring_size = nr_pages * XEN_PAGE_SIZE;
+       unsigned int i;
+       int ret;
+
+       *vaddr = alloc_pages_exact(ring_size, gfp | __GFP_ZERO);
+       if (!*vaddr) {
+               ret = -ENOMEM;
+               goto err;
+       }
+
+       ret = xenbus_grant_ring(dev, *vaddr, nr_pages, grefs);
+       if (ret)
+               goto err;
+
+       return 0;
+
+ err:
+       if (*vaddr)
+               free_pages_exact(*vaddr, ring_size);
+       for (i = 0; i < nr_pages; i++)
+               grefs[i] = INVALID_GRANT_REF;
+       *vaddr = NULL;
+
+       return ret;
+}


We can create a wrapper around this function that will also call 
SHARED_RING_INIT() and FRONT_RING_INIT(). A bunch of drivers do that.


-boris




 


Rackspace

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