Received: by 10.213.65.68 with SMTP id h4csp1082imn; Tue, 27 Mar 2018 14:58:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+20r1HIvmMDAZmPtqMGgUQEouFhjMr/tjni6hMoGod2aJBgmYkkyTjb5B4fxAMdXvr8Gyr X-Received: by 2002:a17:902:1e5:: with SMTP id b92-v6mr1024202plb.78.1522187923362; Tue, 27 Mar 2018 14:58:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522187923; cv=none; d=google.com; s=arc-20160816; b=d3xhTP5CyhPeeVfk62gpLYsN8Lwhn0AbyJTnXVrjpgSiyGFE39wIcEzyZTnhzmpwC7 JzGWoVfbi1cp3c7VN1ooX3jM0lCdWaEy6Qofss67bsmUxD0svobOvHsMKsrmzAIXyDN6 rl5FXicvmZ1uFCd9ryc+QjhB7Ddor3ScNmbeVmgxKz+OpQ75mZJvacq2i8p6bOcVIdCz iGMxsM5jS70RWLEL6CucVhLn5C3v5bcKnOy8s/yUEhPA+97IIPwxDOg3qioJe/rrMCWe juBnSOHwPqdR+gdR8LBvXLtRGqcaEOph4u9C9x7zoNi5QfArGrIfHWrGfUCACjUd+zwP stRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=O6dH5cRvLrSht7KQD739++XPKCCQMg1tYGMJwsSXcyQ=; b=so+VwM+erTjl6n0RbVWJiAN9h6Zv5JlqNCID3Dai5Wzwo6/dKVpfSQrGElJnGMLhoU ENIV5IimgwG+8ZftOPkDwTqpv1w0H1d6PEG7X7iv7w1/K2NfL/q6XDfBYOvpE4V91/47 74iCML9sm1HNGtZMfCVMusyijeel/5aQXeg5xVlSV3nPsqwxaZObASfCnjB2y8MghExo thMyM3T0JtbsqgGSSErPYOpYYTkMqYIL3wxLFrGUTn0FD6FGTSiTz0ELpjrDeOomi8Ga R1JEISeVlOJ8pJkC1auxxJDiKN2ww6YZqgVT8IAPBtecbAlDwAcl3ORTcQFBktAFX6D1 Mumg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ck+oV92D; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d22-v6si2289908pli.625.2018.03.27.14.58.28; Tue, 27 Mar 2018 14:58:43 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=Ck+oV92D; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752031AbeC0V5e (ORCPT + 99 others); Tue, 27 Mar 2018 17:57:34 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:39504 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751020AbeC0V5d (ORCPT ); Tue, 27 Mar 2018 17:57:33 -0400 Received: by mail-pl0-f67.google.com with SMTP id s24-v6so267567plq.6 for ; Tue, 27 Mar 2018 14:57:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=O6dH5cRvLrSht7KQD739++XPKCCQMg1tYGMJwsSXcyQ=; b=Ck+oV92DqcK+Vyzst0F/MMpQAdNGU/2khQpiTfQJ0hcUhLkc7x/Wb5mpmVbCBsozCJ 6utPg7ssShtNj0FcY0oZ3RviTHVYi3pqrYtGWEKpAvZGaoZfRqcaxkkOVUC0go0Md9Af JoeDtwbqJFwCgVXDqRTVK1TLavf21Pi5dPT9vQSDnOazoffG8vezUkqeldIpFkdwfNf0 RWDVPWHEXG5rEEUgqCmuZZ9SR434d6C32SLca1iISoNv9eonybA2Gp4/gsJIjJ8vjPzj MGF4TRNaUk3LfJ03SU2tGxjjVng/S1eRVlF+ccWsxghPZxY/uPHe6gjuIxcdoYr6R2zg UCGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=O6dH5cRvLrSht7KQD739++XPKCCQMg1tYGMJwsSXcyQ=; b=ioeHuknM8UCSK/ShgpBPYdLAM26AhUuJjTZXccvO6TdujLP5//VdeKOChhPXCUZiSS 7Aoapfb1864Sd6zJIxTi4iijNHeZHijRc8rxRUIvOm+tzGcApBX5B+Y4Y9qXgKMS+K8N APZ9tkKASxAWTHQ45ahyBtrr4/3DtFnHVWa7eCvuGEqD0pxpNMcc5JBuWQcN3SHZkL0Y 4ZgMdf/ipdFFo+sowmSWxoNUHapIOKi0RliSS1vLCfknUEowuFXZgKUf4UmJkHQwUlBd NuAlAoibGkUpPWNk+uQp50qIDQPoVZvcRWYFysfff5KbUFiHzxj+zfjeme9xCVEy4Or5 olTw== X-Gm-Message-State: AElRT7GGOIChB2qSSMao0DMdLh70XFeYeizs1XToF3+fBbMXJsuK3luU XSyh4/mB9OKdtGfLCMAbQQw6IA== X-Received: by 2002:a17:902:8d92:: with SMTP id v18-v6mr1000142plo.21.1522187852475; Tue, 27 Mar 2018 14:57:32 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id 67sm5207106pfp.122.2018.03.27.14.57.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 14:57:31 -0700 (PDT) Date: Tue, 27 Mar 2018 14:57:31 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Laurent Dufour cc: paulmck@linux.vnet.ibm.com, peterz@infradead.org, Andrew Morton , kirill@shutemov.name, ak@linux.intel.com, mhocko@kernel.org, dave@stgolabs.net, jack@suse.cz, Matthew Wilcox , benh@kernel.crashing.org, mpe@ellerman.id.au, paulus@samba.org, Thomas Gleixner , Ingo Molnar , hpa@zytor.com, Will Deacon , Sergey Senozhatsky , Andrea Arcangeli , Alexei Starovoitov , kemi.wang@intel.com, sergey.senozhatsky.work@gmail.com, Daniel Jordan , linux-kernel@vger.kernel.org, linux-mm@kvack.org, haren@linux.vnet.ibm.com, khandual@linux.vnet.ibm.com, npiggin@gmail.com, bsingharora@gmail.com, Tim Chen , linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: Re: [PATCH v9 08/24] mm: Protect VMA modifications using VMA sequence count In-Reply-To: <1520963994-28477-9-git-send-email-ldufour@linux.vnet.ibm.com> Message-ID: References: <1520963994-28477-1-git-send-email-ldufour@linux.vnet.ibm.com> <1520963994-28477-9-git-send-email-ldufour@linux.vnet.ibm.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 13 Mar 2018, Laurent Dufour wrote: > diff --git a/mm/mmap.c b/mm/mmap.c > index 5898255d0aeb..d6533cb85213 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -847,17 +847,18 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start, > } > > if (start != vma->vm_start) { > - vma->vm_start = start; > + WRITE_ONCE(vma->vm_start, start); > start_changed = true; > } > if (end != vma->vm_end) { > - vma->vm_end = end; > + WRITE_ONCE(vma->vm_end, end); > end_changed = true; > } > - vma->vm_pgoff = pgoff; > + WRITE_ONCE(vma->vm_pgoff, pgoff); > if (adjust_next) { > - next->vm_start += adjust_next << PAGE_SHIFT; > - next->vm_pgoff += adjust_next; > + WRITE_ONCE(next->vm_start, > + next->vm_start + (adjust_next << PAGE_SHIFT)); > + WRITE_ONCE(next->vm_pgoff, next->vm_pgoff + adjust_next); > } > > if (root) { > @@ -1781,6 +1782,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, > out: > perf_event_mmap(vma); > > + vm_write_begin(vma); > vm_stat_account(mm, vm_flags, len >> PAGE_SHIFT); > if (vm_flags & VM_LOCKED) { > if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) || > @@ -1803,6 +1805,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, > vma->vm_flags |= VM_SOFTDIRTY; > > vma_set_page_prot(vma); > + vm_write_end(vma); > > return addr; > Shouldn't this also protect vma->vm_flags? diff --git a/mm/mmap.c b/mm/mmap.c --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1796,7 +1796,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma == get_gate_vma(current->mm))) mm->locked_vm += (len >> PAGE_SHIFT); else - vma->vm_flags &= VM_LOCKED_CLEAR_MASK; + WRITE_ONCE(vma->vm_flags, + vma->vm_flags & VM_LOCKED_CLEAR_MASK); } if (file) @@ -1809,7 +1810,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, * then new mapped in-place (which must be aimed as * a completely new data area). */ - vma->vm_flags |= VM_SOFTDIRTY; + WRITE_ONCE(vma->vm_flags, vma->vm_flags | VM_SOFTDIRTY); vma_set_page_prot(vma); vm_write_end(vma);