From patchwork Sat Mar 30 21:28:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2368061 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id A4409DF24C for ; Sat, 30 Mar 2013 21:28:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754879Ab3C3V2z (ORCPT ); Sat, 30 Mar 2013 17:28:55 -0400 Received: from mail-gh0-f181.google.com ([209.85.160.181]:55181 "EHLO mail-gh0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754550Ab3C3V2z (ORCPT ); Sat, 30 Mar 2013 17:28:55 -0400 Received: by mail-gh0-f181.google.com with SMTP id 3so189045ghz.26 for ; Sat, 30 Mar 2013 14:28:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding:x-gm-message-state; bh=qWPCOwPbzCXYoQycYg58nFLrCK+nEaNgs5tIOjIVlFU=; b=EV9DRpMMhJUqFYUWRx2ylrJqlpm+T0gdiNXRwY10ydpMvGL4hYo9Zl/oKqI/Ot4niF J83YaRR8GmMw+GYJvRjH4e2vYpqaWFWFHiOwAyM4pFzxH2JIunl+QOSR2f9g2cv5uN4m QQAIvuk8ZJVQT3I9ZTIonAB85PHczvFvggSD+pMa0WGYUAwqmPMrNoedAGMV+uWg2NfU kcKJ/gd8oVINxAfwEw+8IoSY0XVfzZFaL5XOVT9Rr6hlJUuo4DtX/2Aweyafifeua8RW GRm7uGKcYGMI6RMbGRFscD89LSjGPDLohsC2o4GttLoImnmCpOYoMPAbPgMiQezxxEkz wlBg== X-Received: by 10.236.123.75 with SMTP id u51mr2459227yhh.175.1364678934303; Sat, 30 Mar 2013 14:28:54 -0700 (PDT) Received: from [172.22.22.4] (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPS id f27sm12714493yhh.25.2013.03.30.14.28.53 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 30 Mar 2013 14:28:53 -0700 (PDT) Message-ID: <51575915.3060806@inktank.com> Date: Sat, 30 Mar 2013 16:28:53 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 To: "ceph-devel@vger.kernel.org" Subject: [PATCH] libceph: page offset must be less than page size X-Gm-Message-State: ALoCoQlXUReTGnc3f2PVm82hEEOt6bWDxx2RWwKPsdzV4d1tQ0rPACVnmjsH8EIPUrH4PPpupjy0 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Currently ceph_msg_data_pages_advance() allows the page offset value to be PAGE_SIZE, apparently assuming ceph_msg_data_pages_next() will treat it as 0. But that doesn't happen, and the result led to a helpful assertion failure. Change ceph_msg_data_pages_advance() to truncate the offset to 0 before returning if it reaches PAGE_SIZE. Make a few other minor adjustments in this area (comments and a better assertion) while modifying it. This resolves a second issue described in: http://tracker.ceph.com/issues/4598 Signed-off-by: Alex Elder Reviewed-by: Sage Weil --- net/ceph/messenger.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) } @@ -876,14 +876,13 @@ static bool ceph_msg_data_pages_advance(struct ceph_msg_data *data, /* Advance the cursor page offset */ cursor->resid -= bytes; - cursor->page_offset += bytes; - if (!bytes || cursor->page_offset & ~PAGE_MASK) + cursor->page_offset = (cursor->page_offset + bytes) & ~PAGE_MASK; + if (!bytes || cursor->page_offset) return false; /* more bytes to process in the current page */ - /* Move on to the next page */ + /* Move on to the next page; offset is already at 0 */ BUG_ON(cursor->page_index >= cursor->page_count); - cursor->page_offset = 0; cursor->page_index++; cursor->last_piece = cursor->resid <= PAGE_SIZE; @@ -934,8 +933,9 @@ static struct page *ceph_msg_data_pagelist_next(struct ceph_msg_data *data, BUG_ON(!cursor->page); BUG_ON(cursor->offset + cursor->resid != pagelist->length); + /* offset of first page in pagelist is always 0 */ *page_offset = cursor->offset & ~PAGE_MASK; - if (cursor->last_piece) /* pagelist offset is always 0 */ + if (cursor->last_piece) *length = cursor->resid; else *length = PAGE_SIZE - *page_offset; @@ -961,7 +961,7 @@ static bool ceph_msg_data_pagelist_advance(struct ceph_msg_data *data, cursor->resid -= bytes; cursor->offset += bytes; - /* pagelist offset is always 0 */ + /* offset of first page in pagelist is always 0 */ if (!bytes || cursor->offset & ~PAGE_MASK) return false; /* more bytes to process in the current page */ diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index 24f3aba..198b902 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c @@ -766,8 +766,8 @@ static struct page *ceph_msg_data_bio_next(struct ceph_msg_data *data, *length = cursor->resid; else *length = (size_t) (bio_vec->bv_len - cursor->vector_offset); - BUG_ON(*length > PAGE_SIZE); BUG_ON(*length > cursor->resid); + BUG_ON(*page_offset + *length > PAGE_SIZE); return bio_vec->bv_page;