From patchwork Thu Jan 26 19:37:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13117653 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9633C61DA3 for ; Thu, 26 Jan 2023 19:38:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 430536B007E; Thu, 26 Jan 2023 14:38:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B67A8E0001; Thu, 26 Jan 2023 14:38:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E2656B0081; Thu, 26 Jan 2023 14:38:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0D5486B007E for ; Thu, 26 Jan 2023 14:38:11 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E63A41A0F31 for ; Thu, 26 Jan 2023 19:38:10 +0000 (UTC) X-FDA: 80397961140.02.4D77624 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf15.hostedemail.com (Postfix) with ESMTP id 2B262A000A for ; Thu, 26 Jan 2023 19:38:08 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Pfx+wzAh; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3oNbSYwYKCL0vxuhqejrrjoh.frpolqx0-ppnydfn.ruj@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3oNbSYwYKCL0vxuhqejrrjoh.frpolqx0-ppnydfn.ruj@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674761889; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7SychSIO4sUWIo6QruxirbFjx5CbYNnUeHZ00ltQsQk=; b=5Mt7BxMLMquSV+c0ZyuJXxImkg9K7duw8osZIMyoj7T5NXOOyUsgGH50+cmiGQGPBw4Bdm nhg6SRGYUM0UtEcSxh2q5ARlGu4VkTo2RZ3mkPMAoqakxlOlYnD/cLYShu3IuBJAmkLcFP TodN+UoXVFdHyFiUxykzEmpqZj9SfRY= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Pfx+wzAh; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3oNbSYwYKCL0vxuhqejrrjoh.frpolqx0-ppnydfn.ruj@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3oNbSYwYKCL0vxuhqejrrjoh.frpolqx0-ppnydfn.ruj@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674761889; a=rsa-sha256; cv=none; b=KnIIJIhl2HJRfv4t/pWs/ce+Z2UBCunJXxo2E5VgJ93e5bk4ubuLdhGP50BLliCFeJM3Hi i3MGx/96t2OyO8qa5Qobzbsf4kVZu2rG8KfmDlHo/zuJUNZdvEqtwsl53DfVIlG49nOzHt mwJWAiwGqVjDN58pNYw8OpbK2Ubqaa0= Received: by mail-yb1-f201.google.com with SMTP id n203-20020a2572d4000000b0078f09db9888so2930998ybc.18 for ; Thu, 26 Jan 2023 11:38:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=7SychSIO4sUWIo6QruxirbFjx5CbYNnUeHZ00ltQsQk=; b=Pfx+wzAhZ6kKsJzDDedQ8LJwSdqFciZXcllolwp4vBQ+2oIO3zY1GANQzoJfCZWzvE CQPh21a5oWziH93KMEhfcmcYLI66KcWMq+wv9dH36RAXDaWDj3mhxF37O3hO+Nm3j333 DQpz5N93q63IgXjq4N824biP5tt/Btbtpk79Xp1oY2XkCbJniy2hm75eubONJlrUyJHz 4nhnfw5vwu2MM7c8JHS86kwr5IkxCGiAvk+B0fbplC2co4C0HnFTpw4esf89gAkAXtE3 btQ+U4BHBe8XCXeuy8OqZ9E2kM4KncMQmpjGCBcfb2U1tiWjIaGyYCULw+IAQrOfXIUP +Htg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7SychSIO4sUWIo6QruxirbFjx5CbYNnUeHZ00ltQsQk=; b=JhPJOZ0dp2vPoACXtQzrPv43beGqBFcFv78TWXpxbvCMI7tJlfZDoBVxCk3aJke6t8 DBV0axVld3Qs1gH2/dS1zlFbHqmjga70jYJ2mDWcQSqrnlNAiTCvtC3kcE3xSxHUAC+R k2bW1vmS02KtzhV4U/2YKgU26uNzoANPnEv4PMcZqTJ4r4SNOudIYmVzji2Zm7/khLFN 7iSjBfAXwb+5Z8ykxa3Wmre4sKnb54+TDZm/wqwbI6zSr1qaVx5DSfeQJMBNYUq8G+z0 Z5QugG+YmKSdr8NehrxSgOWs/4INTJhUyjIDjxrrrb7+k8+EnktYF+jop5k6mlOAHMig PG/w== X-Gm-Message-State: AFqh2kpMf3dInc3BKieKCjYjwdT6rb3UlEUf/h6+CDfV8Gs1UdNfOtTm dGP2htUijZsOIsi/4B4jRAR1KhW2kY4= X-Google-Smtp-Source: AMrXdXsXS6jvs2FLo8wLjzpNR7510A/NF2577gEg88y5p+yBM43aas9S20uDvZYfhxK8qIb0YJZmeRS9JA0= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:d774:88af:bab3:648d]) (user=surenb job=sendgmr) by 2002:a5b:2ca:0:b0:7d2:d238:42b4 with SMTP id h10-20020a5b02ca000000b007d2d23842b4mr3963873ybp.526.1674761888262; Thu, 26 Jan 2023 11:38:08 -0800 (PST) Date: Thu, 26 Jan 2023 11:37:50 -0800 In-Reply-To: <20230126193752.297968-1-surenb@google.com> Mime-Version: 1.0 References: <20230126193752.297968-1-surenb@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Message-ID: <20230126193752.297968-6-surenb@google.com> Subject: [PATCH v4 5/7] mm: replace vma->vm_flags indirect modification in ksm_madvise From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, paulmck@kernel.org, mingo@redhat.com, will@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, rppt@kernel.org, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, leewalsh@google.com, posk@google.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, surenb@google.com X-Rspamd-Queue-Id: 2B262A000A X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-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F/EWXWk26tYFErubXkvDAbzBtLKfN4De21/bDzSmddej02AMgGK8rmmSkjjj5DNteKZ8UxnUgqVnT5q0LAs89iKhgmVCdwl7WqTpFUyv0QZkQgdmBVtMryPvWVVnXQTLKXczEvtifaCxQrbm3Rpxsk1B8IaFAhQx4pbIGOtR7GHyWCmjf8Oum+d4cNCMJjWJ6G2QR0JayeOtWob/YGnW0Fwwwgh/zypHy8OKI503LKphFUfx5MqiGAGa7BE47L+d1D/kMN/mAcDPO4/wpuNU41YKQfNTx16BIS0OwP4BMZX9yQjWRGLldg5G4nKRzZt8spQObQHBfcV7gHb8pBv7zm+K2cbIzI/XpVf5iFaV8d/mLaRFToQ4G2dnzhg4x7FmAknoLTuby5b61mIMx48Gi37fmT2rArpkkhfzaiQhUzkKteVKxQLpR9kw7fZfAZPjRe6BzDKO1zog0wk2T+dsvVr+hKGqmSy6UtvDa9J3NgRhhWpFMX62Nn/RQIPE1qznZI+1ZxBwPv02jr5TC4mAoO7ihysDu7U+ZlLAyWuj+cPN6RaS8OSMNsGDlSnUJWozYWRlvqNPVB9pt5lBtSdRNkR2hrLVOQ/BZNZvh2bHU8kLyFAzUlftDKiR2FVLV5lzWyRyCZn0wkeEtk4iqA2Y+mTyd4ZazYBGwBkCyQJ8WCTu8kZsjH+2z9L7h4k278hH+cP1Xdbgha4Gl9atffm40FhsTN3nuiGjP2xQe+fr3XotzKe66yvLcIkJJD3Toj0deRXP9tv0H6pScvQMaXlnGF0nHSA7Af3aRcJt16okRkkYV0L5oyt+Wet+l+IkVld X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Replace indirect modifications to vma->vm_flags with calls to modifier functions to be able to track flag changes and to keep vma locking correctness. Signed-off-by: Suren Baghdasaryan Acked-by: Michal Hocko Acked-by: Mel Gorman Acked-by: Mike Rapoport (IBM) Acked-by: Michael Ellerman (powerpc) Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- arch/powerpc/kvm/book3s_hv_uvmem.c | 6 +++++- arch/s390/mm/gmap.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv_uvmem.c b/arch/powerpc/kvm/book3s_hv_uvmem.c index 1d67baa5557a..709ebd578394 100644 --- a/arch/powerpc/kvm/book3s_hv_uvmem.c +++ b/arch/powerpc/kvm/book3s_hv_uvmem.c @@ -393,6 +393,7 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm, { unsigned long gfn = memslot->base_gfn; unsigned long end, start = gfn_to_hva(kvm, gfn); + unsigned long vm_flags; int ret = 0; struct vm_area_struct *vma; int merge_flag = (merge) ? MADV_MERGEABLE : MADV_UNMERGEABLE; @@ -409,12 +410,15 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm, ret = H_STATE; break; } + /* Copy vm_flags to avoid partial modifications in ksm_madvise */ + vm_flags = vma->vm_flags; ret = ksm_madvise(vma, vma->vm_start, vma->vm_end, - merge_flag, &vma->vm_flags); + merge_flag, &vm_flags); if (ret) { ret = H_STATE; break; } + vm_flags_reset(vma, vm_flags); start = vma->vm_end; } while (end > vma->vm_end); diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c index ab836597419d..5a716bdcba05 100644 --- a/arch/s390/mm/gmap.c +++ b/arch/s390/mm/gmap.c @@ -2587,14 +2587,18 @@ int gmap_mark_unmergeable(void) { struct mm_struct *mm = current->mm; struct vm_area_struct *vma; + unsigned long vm_flags; int ret; VMA_ITERATOR(vmi, mm, 0); for_each_vma(vmi, vma) { + /* Copy vm_flags to avoid partial modifications in ksm_madvise */ + vm_flags = vma->vm_flags; ret = ksm_madvise(vma, vma->vm_start, vma->vm_end, - MADV_UNMERGEABLE, &vma->vm_flags); + MADV_UNMERGEABLE, &vm_flags); if (ret) return ret; + vm_flags_reset(vma, vm_flags); } mm->def_flags &= ~VM_MERGEABLE; return 0;