Skip to contentSkip to conversation

libceph: sparse-read misc fixes

PATCH Superseded [email protected] 2 participants 5 messages Nov 1, 2023 – Nov 6, 2023 Ceph common code (libceph)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover libceph: sparse-read misc fixes

From: Xiubo Li <[email protected]>

V2:
- Remove [1/3] patch from V1.

Xiubo Li (2):
libceph: save and covert sr_datalen to host-endian
libceph: check the data length when finishes

 include/linux/ceph/osd_client.h |  3 ++-
 net/ceph/osd_client.c           | 16 +++++++++++++++-
 2 files changed, 17 insertions(+), 2 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH v2 1/2 libceph: save and covert sr_datalen to host-endian

From: Xiubo Li <[email protected]>

We need to save the real data length to determine exactly how many data we can parse later.

URL: https://tracker.ceph.com/issues/62081

---
 include/linux/ceph/osd_client.h | 3 ++-
 net/ceph/osd_client.c           | 7 ++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
include/linux/ceph/osd_client.h +2 -1
index bf9823956758..f703fb8030de 100644
@@ -45,6 +45,7 @@ enum ceph_sparse_read_state {
 	CEPH_SPARSE_READ_HDR	= 0,
 	CEPH_SPARSE_READ_EXTENTS,
 	CEPH_SPARSE_READ_DATA_LEN,
+	CEPH_SPARSE_READ_DATA_PRE,
 	CEPH_SPARSE_READ_DATA,
 };
 
@@ -64,7 +65,7 @@ struct ceph_sparse_read {
 	u64				sr_req_len;  /* orig request length */
 	u64				sr_pos;      /* current pos in buffer */
 	int				sr_index;    /* current extent index */
-	__le32				sr_datalen;  /* length of actual data */
+	u32				sr_datalen;  /* length of actual data */
 	u32				sr_count;    /* extent count in reply */
 	int				sr_ext_len;  /* length of extent array */
 	struct ceph_sparse_extent	*sr_extent;  /* extent array */
net/ceph/osd_client.c +6 -1
index d3a759e052c8..800a2acec069 100644
@@ -5912,8 +5912,13 @@ static int osd_sparse_read(struct ceph_connection *con,
 		convert_extent_map(sr);
 		ret = sizeof(sr->sr_datalen);
 		*pbuf = (char *)&sr->sr_datalen;
-		sr->sr_state = CEPH_SPARSE_READ_DATA;
+		sr->sr_state = CEPH_SPARSE_READ_DATA_PRE;
 		break;
+	case CEPH_SPARSE_READ_DATA_PRE:
+		/* Convert sr_datalen to host-endian */
+		sr->sr_datalen = le32_to_cpu((__force __le32)sr->sr_datalen);
+		sr->sr_state = CEPH_SPARSE_READ_DATA;
+		fallthrough;
 	case CEPH_SPARSE_READ_DATA:
 		if (sr->sr_index >= count) {
 			sr->sr_state = CEPH_SPARSE_READ_HDR;
Signature · 1 line
2.41.0
#2 lore raw

PATCH v2 2/2 libceph: check the data length when finishes

In reply to [email protected]

From: Xiubo Li <[email protected]>

For sparse reading the real length of the data should equal to the total length from the extent array.

URL: https://tracker.ceph.com/issues/62081

---
 net/ceph/osd_client.c | 9 +++++++++
 1 file changed, 9 insertions(+)
net/ceph/osd_client.c +9 -0
index 800a2acec069..7af35106acaf 100644
@@ -5921,6 +5921,13 @@ static int osd_sparse_read(struct ceph_connection *con,
 		fallthrough;
 	case CEPH_SPARSE_READ_DATA:
 		if (sr->sr_index >= count) {
+			if (sr->sr_datalen && count) {
+				pr_warn_ratelimited("sr_datalen %d sr_index %d count %d\n",
+						    sr->sr_datalen, sr->sr_index,
+						    count);
+				WARN_ON_ONCE(sr->sr_datalen);
+			}
+
 			sr->sr_state = CEPH_SPARSE_READ_HDR;
 			goto next_op;
 		}
@@ -5928,6 +5935,8 @@ static int osd_sparse_read(struct ceph_connection *con,
 		eoff = sr->sr_extent[sr->sr_index].off;
 		elen = sr->sr_extent[sr->sr_index].len;
 
+		sr->sr_datalen -= elen;
+
 		dout("[%d] ext %d off 0x%llx len 0x%llx\n",
 		     o->o_osd, sr->sr_index, eoff, elen);
 
Signature · 1 line
2.41.0
maintainer
#3 lore raw

Re: [PATCH v2 2/2] libceph: check the data length when finishes

Quoted 18 lines · On Wed, Nov 1, 2023 at 1:52 AM <[email protected]> wrote:

From: Xiubo Li <[email protected]>

For sparse reading the real length of the data should equal to the total length from the extent array.

URL: https://tracker.ceph.com/issues/62081

---
 net/ceph/osd_client.c | 9 +++++++++
 1 file changed, 9 insertions(+)
net/ceph/osd_client.c +0 -0
index 800a2acec069..7af35106acaf 100644

net/ceph/osd_client.c static int osd_sparse_read(struct ceph_connection *con, · line 5928

Quoted 8 lines
net/ceph/osd_client.c +5 -0
@@ -5921,6 +5921,13 @@ static int osd_sparse_read(struct ceph_connection *con,
                fallthrough;
        case CEPH_SPARSE_READ_DATA:
                if (sr->sr_index >= count) {
+                       if (sr->sr_datalen && count) {
+                               pr_warn_ratelimited("sr_datalen %d sr_index %d count %d\n",
+                                                   sr->sr_datalen, sr->sr_index,
+                                                   count);
+                               WARN_ON_ONCE(sr->sr_datalen);

Hi Xiubo,

I don't think we need both pr_warn_ratelimited and WARN_ON_ONCE? This is a state machine, so the stack trace that WARN_ON_ONCE would dump is unlikely to be of any help.

Thanks,

Ilya

author
#4 lore raw

Re: [PATCH v2 2/2] libceph: check the data length when finishes

Quoted 28 lines · Ilya Dryomov
Quoted 17 lines · On Wed, Nov 1, 2023 at 1:52 AM <[email protected]> wrote:

From: Xiubo Li <[email protected]>

For sparse reading the real length of the data should equal to the total length from the extent array.

URL: https://tracker.ceph.com/issues/62081

---
  net/ceph/osd_client.c | 9 +++++++++
  1 file changed, 9 insertions(+)
net/ceph/osd_client.c +0 -0
index 800a2acec069..7af35106acaf 100644

net/ceph/osd_client.c static int osd_sparse_read(struct ceph_connection *con, · line 5928

Quoted 8 lines
net/ceph/osd_client.c +5 -0
@@ -5921,6 +5921,13 @@ static int osd_sparse_read(struct ceph_connection *con,
                 fallthrough;
         case CEPH_SPARSE_READ_DATA:
                 if (sr->sr_index >= count) {
+                       if (sr->sr_datalen && count) {
+                               pr_warn_ratelimited("sr_datalen %d sr_index %d count %d\n",
+                                                   sr->sr_datalen, sr->sr_index,
+                                                   count);
+                               WARN_ON_ONCE(sr->sr_datalen);

Hi Xiubo,

Quoted 3 lines

I don't think we need both pr_warn_ratelimited and WARN_ON_ONCE? This is a state machine, so the stack trace that WARN_ON_ONCE would dump is unlikely to be of any help.

Okay, makes sense. Let me remove the WARN_ON_ONCE.

Thanks

- Xiubo

Quoted 4 lines

Thanks,

Ilya