Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1945799pxu; Sun, 6 Dec 2020 12:58:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxLi6IZgkVV+3ANBlT0mtFPKkEFyVckknWcQ4xf+S20cFd09Is2mRe2cAIGujWF/8JvcZOF X-Received: by 2002:a05:6402:312b:: with SMTP id dd11mr17558636edb.308.1607288314878; Sun, 06 Dec 2020 12:58:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607288314; cv=none; d=google.com; s=arc-20160816; b=OhkKhs0LXPcHE/VjlWDMq2sBZ6QQPPqDdb8FsvqzVrXJXtzvgbkcxHcb+kL5NhlCd7 MABYmtDyaDmVeKd64XIIsbQb+Zrj+9ROibYJUlnxkdg3L4j/8VI0dA0n2+6h2WtsoaDP Io30XPC/DSTqTDOHraHgrcz0zHuyJj3AF4xB+meG2HEOhircCkbzfdrEoVEbUfhgso1N zl0P4Leu7N5RcIjGnsJIbs6OiNyv7CIeZyphKAwYllTVACWJgKy/jQlN9Hm60fgNwp6Q vKJ6dC3nHnieD+x0Pty39zjXJbkLue7YEdZZdrvRFnxt/t+8vL8Jmrq7UgsZ0Yzw9wEe p8+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=JjaOew6og4Ma3TgZ9+cKOV5nQwdt07PsMK9VaipXVXo=; b=YY6+Bm4MTtUASd/f060ynVtREtmJ0KD8UIv0BV/7waQ+H/kwnmHGPxI0kyYR1035tI pvx/f9EKWcsX0sALs6qRUnuMP6fZwXU63ueYMzRM7XQEtBBTFjDUgMXSt+FaSAqGv71F gHSmQj9RqjZypO0JLArqbJ9ZNWf1z6HBeII1FWSY0NjvWypqksAewbrCk4Wxu7F1dYYi EHY84gtAzhfjBgEmxl6Gq6uClo+8WrR14VArgYM5E8UAV0YsSijrbcO4PabB9EoJv1w4 tBb1CNZCIwFXyPZjqI8rD7JoLdptzdrje6pRgGFVB9XKbaj6hOsXVWG6Zd02MMQNkwpl yukQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codewreck.org header.s=2 header.b=Kw6fVZE2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codewreck.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g3si7165230edj.521.2020.12.06.12.58.11; Sun, 06 Dec 2020 12:58:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@codewreck.org header.s=2 header.b=Kw6fVZE2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codewreck.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727930AbgLFUyQ (ORCPT + 99 others); Sun, 6 Dec 2020 15:54:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726780AbgLFUyP (ORCPT ); Sun, 6 Dec 2020 15:54:15 -0500 Received: from nautica.notk.org (ipv6.notk.org [IPv6:2001:41d0:1:7a93::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6188CC0613D1; Sun, 6 Dec 2020 12:53:35 -0800 (PST) Received: by nautica.notk.org (Postfix, from userid 1001) id 8F6EAC009; Sun, 6 Dec 2020 21:53:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1607288013; bh=JjaOew6og4Ma3TgZ9+cKOV5nQwdt07PsMK9VaipXVXo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Kw6fVZE2HDNIfSU4yQYDOZlyGHncJmSp4+Jf44efQ5j7AT+fE6r0aQVT1r2BhqUz6 LZQ/u8PAEbDqZmCHgAspLQz3CpX0rk/MaK3/+/O9xGR18Mno8u9JUthL3u9hmA1uZZ p8JfHQ/U32MAbrXSv3lycm2ZVNDUwAtZ+zL1jepJJugl15k+idutduhvMHAzfgMbZT ihzPwkWRiJsLja4h9QVgG4Y8OIprN+oXUqqjTttowPdV0u+6Kps3dLKvsWhSkZ3hDt IMP+MG98XZtfupvzwulKtCCkw4eJhnbWgHKDuXoF7gXGZxXC/LwMfEsZ2oWoyWmVn9 ryiZIMcKj6Wng== Date: Sun, 6 Dec 2020 21:53:18 +0100 From: Dominique Martinet To: Chengguang Xu Cc: ericvh@gmail.com, lucho@ionkov.net, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, v9fs-developer@lists.sourceforge.net Subject: Re: [V9fs-developer] [RFC PATCH] 9p: create writeback fid on shared mmap Message-ID: <20201206205318.GA25257@nautica> References: <20201205130904.518104-1-cgxu519@mykernel.net> <20201206091618.GA22629@nautica> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201206091618.GA22629@nautica> User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dominique Martinet wrote on Sun, Dec 06, 2020: > Chengguang Xu wrote on Sat, Dec 05, 2020: > > If vma is shared and the file was opened for writing, > > we should also create writeback fid because vma may be > > mprotected writable even if now readonly. > > Hm, I guess it makes sense. I had a second look, and generic_file_readonly_mmap uses vma's `vma->vm_flags & VM_MAYWRITE` instead (together with VM_SHARED), while mapping_writably_mapped ultimately basically only seems to validate that the mapping is shared from a look at mapping_map_writable callers? It's not very clear to me. OTOH, VM_MAYWRITE is set anytime we have a shared map where file has been opened read-write, which seems to be what you want with regards to protecting from mprotect calls. How about simply changing check from WRITE to MAYWRITE? v9inode = V9FS_I(inode); mutex_lock(&v9inode->v_mutex); if (!v9inode->writeback_fid && (vma->vm_flags & VM_SHARED) && - (vma->vm_flags & VM_WRITE)) { + (vma->vm_flags & VM_MAYWRITE)) { /* * clone a fid and add it to writeback_fid * we do it during mmap instead of -- Dominique