All of lore.kernel.org
 help / color / mirror / Atom feed
* Kernel fast memory registration API proposal [RFC]
@ 2015-07-10  9:09 Sagi Grimberg
       [not found] ` <559F8BD1.9080308-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
  0 siblings, 1 reply; 68+ messages in thread
From: Sagi Grimberg @ 2015-07-10  9:09 UTC (permalink / raw)
  To: linux-rdma-u79uwXL29TY76Z2rM5mHXA
  Cc: Christoph Hellwig, Jason Gunthorpe, Steve Wise, Or Gerlitz,
	Oren Duer, Chuck Lever, Bart Van Assche, Liran Liss, Hefty, Sean,
	Doug Ledford, Tom Talpey

Hi,

Given the last discussions on our in-kernel memory registration API I
thought I'd propose another approach to address this.

As I said before, I think the stack needs to consolidate on a single
memory registration scheme. That scheme is the standard FRWR.

As you know, MRs have a consumers representation (e.g. ib_mr) and a
provider private context. In order to support generic kernel consumers
registration without enforcing the HW way of registering the memory we
keep the HW specifics in the provider private context.

struct provider_mr {
	u64		*page_list; // or what ever the HW uses
	... <more private stuff> ...
	struct ib_mr	ibmr;
};

And then provide helpers to populate the MR with generic kernel
structures such as struct scatterlist (for scsi and other ULPs),
struct page (for NFS) or struct bio_vec (for block ULPs later on).

/**
   * ib_mr_set_sg() - populate memory region buffers
   *     array from a SG list
   * @mr:          memory region
   * @sg:          sg list
   * @sg_nents:    number of elements in the sg
   *
   * Can fail if the HW is not able to register this
   * sg list. In case of failure - caller is responsible
   * to handle it (bounce-buffer, multiple registrations...)
   */
int ib_mr_set_sg(struct ib_mr *mr,
                  struct scatterlist *sg,
                  unsigned short sg_nents);

/**
   * ib_mr_set_pages() - populate memory region buffers
   *     array from a pages array
   * @mr:          memory region
   * @pages:       struct page array
   * @npages:      number of pages in the page array
   */
int ib_mr_set_pages(struct ib_mr *mr,
                     struct page **pages,
                     unsigned int npages);

In the future we can easily add biovec helper (if needed):
/**
   * ib_mr_set_biovec() - populate memory region buffers
   *     array from a bio_vec
   * @mr:          memory region
   * @bio_vec:     bio vector
   * @bi_vcnt:     number of elements in the bio_vec
   *
   * Can fail if the HW is not able to register this
   * sg list. In case of failure - caller is responsible
   * to handle it (bounce-buffer, multiple registrations...)
   */
int ib_mr_set_biovec(struct ib_mr *mr,
                      struct bio_vec *bio_vec,
                      unsigned short bi_vcnt);

These helpers allows the driver to hide the mechanics of the specific
HW implementation details of memory registration.

We *keep* the FRWR work request interface so the consumers can keep
track of what happens on their queue-pair when registering/invalidating
memory regions. However, the API is dramatically simpler.

struct ib_send_wr {
          ...
          union {
                  ...
                  struct {
                          struct ib_mr    *mr;
                          u64             iova;
                          u32             length;
                          int             access_flags;
                  } fast_reg;
                  ...
          } wr;
          ...
};

We can consider moving the iova and length to the population helpers.
Wasn't sure what is better...


Here is an example of how would a ULP use this:

int my_driver_register_sg(struct scatterlist *sg,
                            unsigned short sg_nents)
{
          struct ib_send_wr frwr, *bad_wr;
          struct ib_mr *mr;
          struct ib_mr_init_attr mr_attr = {
                  .mr_type = IB_MR_TYPE_FAST_REG,
                  .max_reg_descs = sg_nents,
          };

          /*
           * Allocate MR
           * With the MR the driver will allocate a page list
           * in its private context
           */
          mr = ib_create_mr(my_pd, &mr_attr);

          /*
           * Set the SG list in the MR, fail if the sg
	  * list is not well aligned (caller should handle
	  * it) or mr does not have enough room to fit the sg.
           */
          rc = ib_mr_set_sg(mr, sg, sg_nents);
	 if (rc)
		/* HW does not support - Need to handle it */

          /* register the MR */
          frwr.opcode = IB_WR_FAST_REG_MR;
          frwr.wrid = my_wrid;
          frwr.wr.fast_reg.mr = mr;
          frwr.wr.fast_reg.iova = ib_sg_dma_adress(&sg[0]);
          frwr.wr.fast_reg.length = length;
          frwr.wr.fast_reg.access_flags = my_flags;

          ib_post_send(my_qp, &frwr, &bad_wr);

          /* do SEND/RDMA/RECV ... */

          /* Do local invalidate if needed */

          /* Free the MR */
          ib_dereg_mr(mr);
}

This generic approach allows for example to add arbitrary sg list
support just by adding a flag to the mr allocation (which will fail
if the device does not support):

int my_driver_register_arb_sg(struct scatterlist *sg,
                                unsigned short sg_nents)
{
          struct ib_send_wr frwr, *bad_wr;
          struct ib_mr *mr;
          struct ib_mr_init_attr mr_attr = {
                  .mr_type = IB_MR_TYPE_FAST_REG,
                  .create_flags = *IB_MR_REG_ARB_SG*,
                  .max_reg_descs = sg_nents,
          };

	 /* The rest is exactly the same... */
}



That is the general direction,

Thoughts? Comments?

Sagi.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 68+ messages in thread

end of thread, other threads:[~2015-07-21 16:00 UTC | newest]

Thread overview: 68+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-10  9:09 Kernel fast memory registration API proposal [RFC] Sagi Grimberg
     [not found] ` <559F8BD1.9080308-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-11 10:39   ` Christoph Hellwig
     [not found]     ` <20150711103920.GE14741-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2015-07-12  7:57       ` Sagi Grimberg
     [not found]         ` <55A21DF6.6090909-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-12 18:15           ` Chuck Lever
     [not found]             ` <96901C8F-D916-4ECF-8DA4-C5C67FB8539E-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2015-07-13  6:47               ` Christoph Hellwig
     [not found]                 ` <20150713064701.GB31842-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2015-07-13 14:16                   ` Chuck Lever
     [not found]                     ` <1D9C0527-E277-4C3F-A80D-C4FBAA3D82E9-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2015-07-14  8:50                       ` Sagi Grimberg
     [not found]                         ` <55A4CD5B.9030000-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-14 18:58                           ` Chuck Lever
2015-07-13 16:30   ` Jason Gunthorpe
     [not found]     ` <20150713163015.GA23832-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-14  8:39       ` Sagi Grimberg
     [not found]         ` <55A4CABC.5050807-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-14 14:42           ` Steve Wise
2015-07-14 15:33           ` Christoph Hellwig
     [not found]             ` <20150714153347.GA11026-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2015-07-14 15:53               ` Jason Gunthorpe
     [not found]                 ` <20150714155340.GA7399-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-14 16:46                   ` Sagi Grimberg
     [not found]                     ` <55A53CFA.7070509-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-14 17:08                       ` Jason Gunthorpe
     [not found]                         ` <20150714170808.GA19814-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-14 18:07                           ` Steve Wise
2015-07-15  3:05                           ` Doug Ledford
     [not found]                             ` <55A5CDE2.4060904-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-07-15  8:52                               ` Sagi Grimberg
2015-07-14 16:12               ` Sagi Grimberg
     [not found]                 ` <55A534D1.6030008-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-14 16:16                   ` Steve Wise
2015-07-14 17:29                     ` Tom Talpey
2015-07-14 16:35                   ` Jason Gunthorpe
     [not found]                     ` <20150714163506.GC7399-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-14 16:55                       ` Sagi Grimberg
     [not found]                         ` <55A53F0B.5050009-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-14 17:09                           ` Jason Gunthorpe
     [not found]                             ` <20150714170859.GB19814-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-15  8:01                               ` Sagi Grimberg
     [not found]                                 ` <55A6136A.8010204-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-15 14:32                                   ` Chuck Lever
     [not found]                                     ` <A9EF2F26-E737-4E80-B2E3-F8D6406F9893-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2015-07-15 14:39                                       ` Chuck Lever
2015-07-15 17:19                                       ` Jason Gunthorpe
     [not found]                                         ` <20150715171926.GB23588-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-15 18:39                                           ` Steve Wise
2015-07-15 21:25                                           ` Chuck Lever
     [not found]                                             ` <F2C64EE9-38A5-4DEE-B60E-AD8430FE1049-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2015-07-15 22:49                                               ` Jason Gunthorpe
     [not found]                                                 ` <20150715224928.GA941-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-16 14:45                                                   ` Chuck Lever
     [not found]                                                     ` <F0518DEF-D43C-4CB6-89ED-CA3E94A4DD72-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2015-07-16 14:56                                                       ` Steve Wise
2015-07-16 17:40                                                       ` Jason Gunthorpe
     [not found]                                                         ` <20150716174046.GB3680-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-16 20:07                                                           ` Chuck Lever
     [not found]                                                             ` <F8484ABB-BED9-463F-8AEA-EB898EBDD93C-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2015-07-16 20:49                                                               ` Jason Gunthorpe
     [not found]                                                                 ` <20150716204932.GA10638-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-17 15:03                                                                   ` Chuck Lever
     [not found]                                                                     ` <62F9F5B8-0A18-4DF8-B47E-7408BFFE9904-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2015-07-17 17:21                                                                       ` Jason Gunthorpe
     [not found]                                                                         ` <20150717172141.GA15808-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-17 19:26                                                                           ` Chuck Lever
     [not found]                                                                             ` <9A70883F-9963-42D0-9F5C-EF49F822A037-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2015-07-17 20:36                                                                               ` Jason Gunthorpe
2015-07-16  6:52                                       ` Sagi Grimberg
     [not found]                                         ` <55A754BC.6010706-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-16  8:07                                           ` Christoph Hellwig
     [not found]                                             ` <20150716080702.GD9093-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2015-07-16  8:29                                               ` Sagi Grimberg
     [not found]                                                 ` <55A76B84.30504-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-16 14:25                                                   ` Steve Wise
2015-07-16 14:40                                                     ` Sagi Grimberg
2015-07-15 18:31                                   ` Jason Gunthorpe
     [not found]                                     ` <20150715183129.GC23588-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-15 18:50                                       ` Steve Wise
2015-07-15 19:09                                         ` Jason Gunthorpe
     [not found]                                           ` <20150715190947.GE23588-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-15 19:26                                             ` Steve Wise
2015-07-16  8:02                                       ` Christoph Hellwig
2015-07-15  7:32   ` Christoph Hellwig
     [not found]     ` <20150715073233.GA11535-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2015-07-15  8:33       ` Sagi Grimberg
     [not found]         ` <55A61AE3.8020609-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-15  9:07           ` Christoph Hellwig
2015-07-15 19:15           ` Jason Gunthorpe
2015-07-15 17:07       ` Jason Gunthorpe
     [not found]         ` <20150715170750.GA23588-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-16 12:21           ` Sagi Grimberg
     [not found]             ` <55A7A1B0.5000808-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-16 18:08               ` Jason Gunthorpe
     [not found]                 ` <20150716180806.GC3680-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-19  5:33                   ` Sagi Grimberg
     [not found]                     ` <55AB36A4.1070102-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-20 16:23                       ` Jason Gunthorpe
     [not found]                         ` <20150720162340.GB18336-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-20 16:29                           ` Sagi Grimberg
2015-07-19  5:45   ` Sagi Grimberg
     [not found]     ` <55AB3976.7060202-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-20 16:18       ` Jason Gunthorpe
     [not found]         ` <20150720161821.GA18336-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-20 16:27           ` Sagi Grimberg
     [not found]             ` <55AD2188.50708-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-20 17:00               ` Jason Gunthorpe
     [not found]                 ` <20150720170033.GA20350-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-20 17:07                   ` Sagi Grimberg
     [not found]                     ` <55AD2AB4.8010209-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-20 19:50                       ` Jason Gunthorpe
     [not found]                         ` <20150720195027.GA24162-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-07-21 11:40                           ` Sagi Grimberg
     [not found]                             ` <55AE2FA2.3000601-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-07-21 16:00                               ` Jason Gunthorpe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.