From patchwork Wed Jan 25 23:35:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13116405 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 D412FC27C76 for ; Wed, 25 Jan 2023 23:36:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 395FD6B007E; Wed, 25 Jan 2023 18:36:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 344A26B0080; Wed, 25 Jan 2023 18:36:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 170C96B0081; Wed, 25 Jan 2023 18:36:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 069CB6B007E for ; Wed, 25 Jan 2023 18:36:12 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E0D21A0274 for ; Wed, 25 Jan 2023 23:36:11 +0000 (UTC) X-FDA: 80394932142.06.A1CB4FD Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf22.hostedemail.com (Postfix) with ESMTP id 3076FC000A for ; Wed, 25 Jan 2023 23:36:09 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=mIcpdtGt; spf=pass (imf22.hostedemail.com: domain of 36bzRYwYKCM4CEBy7v08805y.w86527EH-664Fuw4.8B0@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=36bzRYwYKCM4CEBy7v08805y.w86527EH-664Fuw4.8B0@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674689770; 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=uFNiofQkx8EGkioLCgUuZFMgiu7EagxK9ILw1Sow0vM=; b=O2QAVbffGfZqw6YSNU1eXEtX4oQWL0FLBvQ50vTUqleelrVB1J5FKQV8f6YVfUuxbiBBFt bG/0SMCI9Qb7Bg7X9IC9tfmV6h1f5HwvcqDpC6qaOMreiZGylbL7tuT3Bl7UBlwa14azYu bxfADO6FfT6U5YRMd93EsfwSqK4M09g= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=mIcpdtGt; spf=pass (imf22.hostedemail.com: domain of 36bzRYwYKCM4CEBy7v08805y.w86527EH-664Fuw4.8B0@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=36bzRYwYKCM4CEBy7v08805y.w86527EH-664Fuw4.8B0@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674689770; a=rsa-sha256; cv=none; b=a+r27WpbeGHjHSSStjG+0i48JZodTs15Q6XuJO1tk0Ogf7VJyi46onaHvZ7WVe84nG3n8w 29PsvBPd/T3CzgURRmrK/zJ0S6KfD6UJDR2nzWedxDkCgroCmMNXlX7yy1/GEmvbBT9nMj xQX5XyhH7zg0dog9I7LuGbJsY32weD4= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-507aac99fdfso1422087b3.11 for ; Wed, 25 Jan 2023 15:36:09 -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=uFNiofQkx8EGkioLCgUuZFMgiu7EagxK9ILw1Sow0vM=; b=mIcpdtGtTptlXBa8kzPRiZ4LQeL8L4qFSrls4nVpFeCNpMiSotY6f+paMy+LghZ8V6 e9l5UcyWL072m000YU0+L04zrVr4EhWAwoZTx/p7MV2c+3YkTz0Vc17xg7GsN6zD4Z9R fONlZs10IIrOred9HnpC0C3EFZJdB0XAfbhzeR0ZgQ/dkYvIT6XW43EAfnRvkqq66q3g TyPxEoXRoXVo+FH/WvNzfXLvwh7J86Ui+UKVO/3Scbbi/do79F5NcZ+HTnfVO2bahnkQ 86T/MKLgW1x3swE+dFhZ6o7oKt9I4CYoHoHaBYMQWqHMdLwEjkwoM3UIGDBmnlaN/XJj pP8w== 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=uFNiofQkx8EGkioLCgUuZFMgiu7EagxK9ILw1Sow0vM=; b=PPqW5H/lkOT5IPI6NJQc5/aoLHHgXlXieti+6UKUtjUdw8vJfD87toAt2mCHEwMP9f +Rlv3wpKwqAQtNUjxIg497OLz4zzgKcykZHsIoa7/zQ9DcNF0zsAj/hIDpMUvxES1/sN th0mh9HQl/MV1aai8fcNi8RMhF1lfcWNuHzVCkAPMG2wCxzo0DLDWqmVXYgQqv3hmv9t akgj51fCAAuqxmpvod+bOq3AGm4sczZvAFIOEtTj6m0ESn4UQzH7GU/Y3sxq7Z/SyOPx 8s5HKhoz7WNbSqQSQAP73EGmvBNoWZKpdi8EHG8eeGCHUWYBCpF0Q7ezPMOsLFC+17eV Ec0w== X-Gm-Message-State: AFqh2koricBJKzAfanYTo/4NaznRHiMPx5tDzcC2PdS2MhN0yjHhdh37 4p9B0KHqkg5ICF4Cyh3O7zyOSZar6tA= X-Google-Smtp-Source: AMrXdXvMdRhk8RmJeZj9msjjVduAuvJeB5wZmXR/kRnEPyHhZJwnM0jGg8ZrEwM+ym7wuYAnXhndpOMqpaU= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:f7b0:20e8:ce66:f98]) (user=surenb job=sendgmr) by 2002:a0d:e582:0:b0:4df:96d1:f67a with SMTP id o124-20020a0de582000000b004df96d1f67amr4204399ywe.246.1674689769324; Wed, 25 Jan 2023 15:36:09 -0800 (PST) Date: Wed, 25 Jan 2023 15:35:52 -0800 In-Reply-To: <20230125233554.153109-1-surenb@google.com> Mime-Version: 1.0 References: <20230125233554.153109-1-surenb@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Message-ID: <20230125233554.153109-6-surenb@google.com> Subject: [PATCH v3 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, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, hughlynch@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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3076FC000A X-Stat-Signature: j6858ewqufnwo546jx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Q/ib4Thxr5N7EoQZOvk+ePAFx6f5Y5tGSN/AH8B+6rsvGhl7gFCVPyJx96nCk8cKbPugrBJ/RQW+Oeq4mhiPyv0w51+CloWi2ZJboVG2Y+ajet3aAAkGkKzo3sO7oiutgBF2hKgYO3XYXxVs+aJB9dwESHnNXStsoLQ7rSyEz3xWBC2Gle+GLOMubBJoymNChsZUYVUJDDnMO7xSnPAbEvoJXJiAg6fNw7CO0+pQ+nQm7cu1rR1kLXOb36DIicpdMoDWgTKlyruWI0UdrL3h9ehjXKdBxOpVS2y6VijnGsd3OiSSqIURC6c/miEZdvNksuYJk7Y87MRc++QcXKqrikslrNbSv+kGPpHTSNn0H1pnyL/RKLWxQYOPlR55PH43QEEaDdkewgtqBVhF3Pxl47wUcEVAeHjqzxc39a8+VReWLfDntWskYuU4KyowHT6VJxTa06Hj81L9BDbMEjVoF6Pot0ax9ZXXgcNIGP9CkiyzublHwKTW4Wtd8mtLXaylm+BGaWdyjOLkkclD35emRbFsi5bDB9Tv5vbS/Pto+7Yi1eAra6rx7xk7bw728diO+B2MwDX5mIRaLsx9oGFvCsSifDAAfIpAIFu/dbU6m7KttRs6jtJKFtMY8PHctKY346xXIVcfWxWkFs1IQ/D4ydpo6rctdqLYtt/gO+EEb0kB5VWMAfjT9Zr4qg= 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 --- arch/powerpc/kvm/book3s_hv_uvmem.c | 5 ++++- arch/s390/mm/gmap.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv_uvmem.c b/arch/powerpc/kvm/book3s_hv_uvmem.c index 1d67baa5557a..325a7a47d348 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,14 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm, ret = H_STATE; break; } + 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; } + reset_vm_flags(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 3a695b8a1e3c..d5eb47dcdacb 100644 --- a/arch/s390/mm/gmap.c +++ b/arch/s390/mm/gmap.c @@ -2587,14 +2587,17 @@ 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) { + 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; + reset_vm_flags(vma, vm_flags); } mm->def_flags &= ~VM_MERGEABLE; return 0;