tree a491f9b095ed340d0e284fab5ee2575c8db667df
parent 2f05e40f94584da6f8045467ca4dbf90f128f879
author Roland Dreier <[EMAIL PROTECTED]> Tue Apr 12 08:26:50 2005
committer Linus Torvalds <[EMAIL PROTECTED]> Tue Apr 12 08:26:50 2005

[PATCH] IB/mthca: fix MTT allocation in mem-free mode

Fix bug in MTT allocation in mem-free mode.

I misunderstood the MTT size value returned by the firmware -- it is really
the size of a single MTT entry, since mem-free mode does not segment the MTT
as the original firmware did.  This meant that our MTT addresses ended up
being off by a factor of 8.  This meant that our MTT allocations might
overlap, and so we could overwrite and corrupt earlier memory regions when
writing new MTT entries.

We fix this by always using our 64-byte MTT segment size.  This allows some
simplification of the code as well, since there's no reason to put the MTT
segment size in a variable -- we can always use our enum value directly.

Signed-off-by: Roland Dreier <[EMAIL PROTECTED]>
Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>

 mthca_cmd.c     |    2 --
 mthca_cmd.h     |    1 -
 mthca_dev.h     |    1 -
 mthca_main.c    |    2 +-
 mthca_mr.c      |    6 +++---
 mthca_profile.c |    5 ++---
 6 files changed, 6 insertions(+), 11 deletions(-)

Index: drivers/infiniband/hw/mthca/mthca_cmd.c
===================================================================
--- 
0612ad8ee0fd7318f6d8613ddf60ea7f898bd593/drivers/infiniband/hw/mthca/mthca_cmd.c
  (mode:100644 sha1:d4cfd85a5f02bc39d430042dd5ef33a5c5f8e47e)
+++ 
a491f9b095ed340d0e284fab5ee2575c8db667df/drivers/infiniband/hw/mthca/mthca_cmd.c
  (mode:100644 sha1:b0b5b1b3b44405a56f1ca578d94fe3cbfc87b0f8)
@@ -990,7 +990,6 @@
                MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SG_RQ_OFFSET);
                dev_lim->max_sg = min_t(int, field, dev_lim->max_sg);
                MTHCA_GET(size, outbox, QUERY_DEV_LIM_MTT_ENTRY_SZ_OFFSET);
-               dev_lim->mtt_seg_sz = size;
                MTHCA_GET(size, outbox, QUERY_DEV_LIM_MPT_ENTRY_SZ_OFFSET);
                dev_lim->mpt_entry_sz = size;
                MTHCA_GET(field, outbox, QUERY_DEV_LIM_PBL_SZ_OFFSET);
@@ -1018,7 +1017,6 @@
        } else {
                MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_AV_OFFSET);
                dev_lim->hca.tavor.max_avs = 1 << (field & 0x3f);
-               dev_lim->mtt_seg_sz   = MTHCA_MTT_SEG_SIZE;
                dev_lim->mpt_entry_sz = MTHCA_MPT_ENTRY_SIZE;
        }
 
Index: drivers/infiniband/hw/mthca/mthca_cmd.h
===================================================================
--- 
0612ad8ee0fd7318f6d8613ddf60ea7f898bd593/drivers/infiniband/hw/mthca/mthca_cmd.h
  (mode:100644 sha1:f34655777d6fb4967f21bca11555bbe99d265f70)
+++ 
a491f9b095ed340d0e284fab5ee2575c8db667df/drivers/infiniband/hw/mthca/mthca_cmd.h
  (mode:100644 sha1:b751b83851306a4ba2ec14af01389be68af4b717)
@@ -162,7 +162,6 @@
        int cqc_entry_sz;
        int srq_entry_sz;
        int uar_scratch_entry_sz;
-       int mtt_seg_sz;
        int mpt_entry_sz;
        union {
                struct {
Index: drivers/infiniband/hw/mthca/mthca_dev.h
===================================================================
--- 
0612ad8ee0fd7318f6d8613ddf60ea7f898bd593/drivers/infiniband/hw/mthca/mthca_dev.h
  (mode:100644 sha1:f2af8316e0bd5927ad3a843fd32c50f3259185aa)
+++ 
a491f9b095ed340d0e284fab5ee2575c8db667df/drivers/infiniband/hw/mthca/mthca_dev.h
  (mode:100644 sha1:695ec26a156cbc81cb7eb5c2f229922b9e9a35f3)
@@ -121,7 +121,6 @@
        int      reserved_eqs;
        int      num_mpts;
        int      num_mtt_segs;
-       int      mtt_seg_size;
        int      reserved_mtts;
        int      reserved_mrws;
        int      reserved_uars;
Index: drivers/infiniband/hw/mthca/mthca_main.c
===================================================================
--- 
0612ad8ee0fd7318f6d8613ddf60ea7f898bd593/drivers/infiniband/hw/mthca/mthca_main.c
  (mode:100644 sha1:99fd717488362ea3c5a5dfe89b848c2baa6a0f40)
+++ 
a491f9b095ed340d0e284fab5ee2575c8db667df/drivers/infiniband/hw/mthca/mthca_main.c
  (mode:100644 sha1:8c2fd0c71e517f4a583f915a22d70b8b727b2362)
@@ -390,7 +390,7 @@
        }
 
        mdev->mr_table.mtt_table = mthca_alloc_icm_table(mdev, 
init_hca->mtt_base,
-                                                        dev_lim->mtt_seg_sz,
+                                                        MTHCA_MTT_SEG_SIZE,
                                                         
mdev->limits.num_mtt_segs,
                                                         
mdev->limits.reserved_mtts, 1);
        if (!mdev->mr_table.mtt_table) {
Index: drivers/infiniband/hw/mthca/mthca_mr.c
===================================================================
--- 
0612ad8ee0fd7318f6d8613ddf60ea7f898bd593/drivers/infiniband/hw/mthca/mthca_mr.c 
 (mode:100644 sha1:6603168b5bfce4d42769c4b849148aa8e6f00005)
+++ 
a491f9b095ed340d0e284fab5ee2575c8db667df/drivers/infiniband/hw/mthca/mthca_mr.c 
 (mode:100644 sha1:a7ed51dc97fe5715e3ab16b2789f82cf91c3b55a)
@@ -263,7 +263,7 @@
                        goto err_out_mpt_free;
        }
 
-       for (i = dev->limits.mtt_seg_size / 8, mr->order = 0;
+       for (i = MTHCA_MTT_SEG_SIZE / 8, mr->order = 0;
             i < list_len;
             i <<= 1, ++mr->order)
                ; /* nothing */
@@ -286,7 +286,7 @@
        mtt_entry = MAILBOX_ALIGN(mailbox);
 
        mtt_entry[0] = cpu_to_be64(dev->mr_table.mtt_base +
-                                  mr->first_seg * dev->limits.mtt_seg_size);
+                                  mr->first_seg * MTHCA_MTT_SEG_SIZE);
        mtt_entry[1] = 0;
        for (i = 0; i < list_len; ++i)
                mtt_entry[i + 2] = cpu_to_be64(buffer_list[i] |
@@ -330,7 +330,7 @@
        memset(&mpt_entry->lkey, 0,
               sizeof *mpt_entry - offsetof(struct mthca_mpt_entry, lkey));
        mpt_entry->mtt_seg   = cpu_to_be64(dev->mr_table.mtt_base +
-                                          mr->first_seg * 
dev->limits.mtt_seg_size);
+                                          mr->first_seg * MTHCA_MTT_SEG_SIZE);
 
        if (0) {
                mthca_dbg(dev, "Dumping MPT entry %08x:\n", mr->ibmr.lkey);
Index: drivers/infiniband/hw/mthca/mthca_profile.c
===================================================================
--- 
0612ad8ee0fd7318f6d8613ddf60ea7f898bd593/drivers/infiniband/hw/mthca/mthca_profile.c
  (mode:100644 sha1:ad0a2df724f6a5c1091504a83931fc8d578921f3)
+++ 
a491f9b095ed340d0e284fab5ee2575c8db667df/drivers/infiniband/hw/mthca/mthca_profile.c
  (mode:100644 sha1:9c2b2a2f180b5af9f8d43d9860eb3ab2c13ebce9)
@@ -95,7 +95,7 @@
        profile[MTHCA_RES_RDB].size  = MTHCA_RDB_ENTRY_SIZE;
        profile[MTHCA_RES_MCG].size  = MTHCA_MGM_ENTRY_SIZE;
        profile[MTHCA_RES_MPT].size  = dev_lim->mpt_entry_sz;
-       profile[MTHCA_RES_MTT].size  = dev_lim->mtt_seg_sz;
+       profile[MTHCA_RES_MTT].size  = MTHCA_MTT_SEG_SIZE;
        profile[MTHCA_RES_UAR].size  = dev_lim->uar_scratch_entry_sz;
        profile[MTHCA_RES_UDAV].size = MTHCA_AV_SIZE;
        profile[MTHCA_RES_UARC].size = request->uarc_size;
@@ -229,10 +229,9 @@
                        break;
                case MTHCA_RES_MTT:
                        dev->limits.num_mtt_segs = profile[i].num;
-                       dev->limits.mtt_seg_size = dev_lim->mtt_seg_sz;
                        dev->mr_table.mtt_base   = profile[i].start;
                        init_hca->mtt_base       = profile[i].start;
-                       init_hca->mtt_seg_sz     = ffs(dev_lim->mtt_seg_sz) - 7;
+                       init_hca->mtt_seg_sz     = ffs(MTHCA_MTT_SEG_SIZE) - 7;
                        break;
                case MTHCA_RES_UAR:
                        dev->limits.num_uars       = profile[i].num;
-
To unsubscribe from this list: send the line "unsubscribe bk-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to