Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp228153imm; Wed, 29 Aug 2018 19:21:48 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdas7Cu7DE+dl36Z2GEV+4Gz5sV6Jnb5/PaQox1xJOBgfOwD9Q6Z/eGh8mRmj91wHhxlHBqP X-Received: by 2002:a63:bd41:: with SMTP id d1-v6mr7926445pgp.309.1535595708147; Wed, 29 Aug 2018 19:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535595708; cv=none; d=google.com; s=arc-20160816; b=H6DVS0zJV1jXRM01Edbx4xOtiky+V1wk7F1f9xhPcxLoJUf/I2oq5TDlcTX9h6ufF6 78UnxcwiJkU8T2bKV1i6Z3MGWoaFOG9CEXy8rJ82OOob9SgBOexjYJPfbU0SVmlx4Vum C5dc05/ReOcUGumVSJmP/gHR4wVmY7ijB7FmowcvX9D6eafjoPR6P/KwO/zAZHNSt1dM 1ayVbe5qZpWRG0wSi/ZmqtHkt/wR1gDyaP2jBlUx5y2FlYuPE5ysLEhObJPtY7uvGiW/ 3a+/iA5EMDRst3HigrRnznOXwtedH4RJxpNlp1KxON4rT7ATx7quHpNbeM8xiTdCsj26 2elw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:arc-authentication-results; bh=J7nTBSMmD+a6rBlPfZ6sSMd41gYZxqcacYzvuq8tvP0=; b=B32B5+DperNZGrW4g6PJfTkmHbgfjye7wMHoHgVRd6M9UrWq6PiNn0zNeCybPrS+no WOmjUZDSe8H9/r+brgb2+iwcbB2M6hLR98nbkBZ4HJ1KqIrbIRfozJmFFVPfWAqS6AlE B/3CepSLCo5gAgIU8MuROSy7QUw2Vma/kiM+t54hBb7+0m7SsTyRCrdS6zt/nUBj8Y5F M3YUxcfJ+zqFh5cbUG7pizrzBzapTau/FTQd/1so/9dNYe5ge3G2pPqg3DggMUBM8vIQ QeTVFMFAPB5PgRERUYI5pEmCcml3vBUfzwLm4DFy8iVVqsOUKSxGRJYRhenosxPdBVgr e9GQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7-v6si5395797pgw.207.2018.08.29.19.21.32; Wed, 29 Aug 2018 19:21:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727331AbeH3GUF (ORCPT + 99 others); Thu, 30 Aug 2018 02:20:05 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:11206 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727178AbeH3GUE (ORCPT ); Thu, 30 Aug 2018 02:20:04 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id C949956943FFB; Thu, 30 Aug 2018 10:20:14 +0800 (CST) Received: from [127.0.0.1] (10.134.22.195) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.399.0; Thu, 30 Aug 2018 10:20:12 +0800 Subject: Re: [PATCH v2] f2fs: avoid wrong decrypted data from disk To: Jaegeuk Kim , , References: <20180827225226.14272-1-jaegeuk@kernel.org> <20180830014858.GA91444@jaegeuk-macbookpro.roam.corp.google.com> From: Chao Yu Message-ID: Date: Thu, 30 Aug 2018 10:20:12 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180830014858.GA91444@jaegeuk-macbookpro.roam.corp.google.com> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018/8/30 9:48, Jaegeuk Kim wrote: > 1. Create a file in an encrypted directory > 2. Do GC & drop caches > 3. Read stale data before its bio for metapage was not issued yet > > Signed-off-by: Jaegeuk Kim > --- > Change log from v1: > - move to bio != NULL > > fs/f2fs/data.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > index 382c1ef9a9e4..159e411785e9 100644 > --- a/fs/f2fs/data.c > +++ b/fs/f2fs/data.c > @@ -1556,6 +1556,12 @@ static int f2fs_mpage_readpages(struct address_space *mapping, > bio = NULL; > goto set_error_page; > } > + } else if (unlikely(f2fs_encrypted_file(inode))) { For android scenario, encryption becomes a common case now, so I think we can remove unlikely here. > + /* > + * If the page is under writeback, we need to wait for > + * its completion to see the correct decrypted data. > + */ > + f2fs_wait_on_block_writeback(F2FS_I_SB(inode), block_nr); > } Look at this again, it seems f2fs_wait_on_block_writeback() is not related to f2fs_grab_read_bio(), so we can move it here to make code logic more clear: if (f2fs_encrypted_file(inode)) { /* */ f2fs_wait_on_block_writeback(F2FS_I_SB(inode), block_nr); } Also, in f2fs_submit_page_read(), we need to adjust to: - f2fs_grab_read_bio() - f2fs_wait_on_block_writeback() - bio_add_page() How do you think? Thanks, > > if (bio_add_page(bio, page, blocksize, 0) < blocksize) >