[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y9JHYvihjxGpAFPg@kernel.org>
Date: Thu, 26 Jan 2023 11:26:58 +0200
From: Mike Rapoport <rppt@...nel.org>
To: Suren Baghdasaryan <surenb@...gle.com>
Cc: akpm@...ux-foundation.org, michel@...pinasse.org,
jglisse@...gle.com, mhocko@...e.com, vbabka@...e.cz,
hannes@...xchg.org, mgorman@...hsingularity.net, dave@...olabs.net,
willy@...radead.org, liam.howlett@...cle.com, peterz@...radead.org,
ldufour@...ux.ibm.com, paulmck@...nel.org, luto@...nel.org,
songliubraving@...com, peterx@...hat.com, david@...hat.com,
dhowells@...hat.com, hughd@...gle.com, bigeasy@...utronix.de,
kent.overstreet@...ux.dev, punit.agrawal@...edance.com,
lstoakes@...il.com, peterjung1337@...il.com, rientjes@...gle.com,
axelrasmussen@...gle.com, joelaf@...gle.com, minchan@...gle.com,
jannh@...gle.com, shakeelb@...gle.com, tatashin@...gle.com,
edumazet@...gle.com, gthelen@...gle.com, gurua@...gle.com,
arjunroy@...gle.com, soheil@...gle.com, hughlynch@...gle.com,
leewalsh@...gle.com, posk@...gle.com, will@...nel.org,
aneesh.kumar@...ux.ibm.com, npiggin@...il.com,
chenhuacai@...nel.org, tglx@...utronix.de, mingo@...hat.com,
bp@...en8.de, dave.hansen@...ux.intel.com, richard@....at,
anton.ivanov@...bridgegreys.com, johannes@...solutions.net,
qianweili@...wei.com, wangzhou1@...ilicon.com,
herbert@...dor.apana.org.au, davem@...emloft.net, vkoul@...nel.org,
airlied@...il.com, daniel@...ll.ch,
maarten.lankhorst@...ux.intel.com, mripard@...nel.org,
tzimmermann@...e.de, l.stach@...gutronix.de,
krzysztof.kozlowski@...aro.org, patrik.r.jakobsson@...il.com,
matthias.bgg@...il.com, robdclark@...il.com,
quic_abhinavk@...cinc.com, dmitry.baryshkov@...aro.org,
tomba@...nel.org, hjc@...k-chips.com, heiko@...ech.de,
ray.huang@....com, kraxel@...hat.com, sre@...nel.org,
mcoquelin.stm32@...il.com, alexandre.torgue@...s.st.com,
tfiga@...omium.org, m.szyprowski@...sung.com, mchehab@...nel.org,
dimitri.sivanich@....com, zhangfei.gao@...aro.org,
jejb@...ux.ibm.com, martin.petersen@...cle.com,
dgilbert@...erlog.com, hdegoede@...hat.com, mst@...hat.com,
jasowang@...hat.com, alex.williamson@...hat.com, deller@....de,
jayalk@...works.biz, viro@...iv.linux.org.uk, nico@...xnic.net,
xiang@...nel.org, chao@...nel.org, tytso@....edu,
adilger.kernel@...ger.ca, miklos@...redi.hu,
mike.kravetz@...cle.com, muchun.song@...ux.dev, bhe@...hat.com,
andrii@...nel.org, yoshfuji@...ux-ipv6.org, dsahern@...nel.org,
kuba@...nel.org, pabeni@...hat.com, perex@...ex.cz, tiwai@...e.com,
haojian.zhuang@...il.com, robert.jarzmik@...e.fr,
linux-mm@...ck.org, linux-arm-kernel@...ts.infradead.org,
linuxppc-dev@...ts.ozlabs.org, x86@...nel.org,
linux-kernel@...r.kernel.org, linux-graphics-maintainer@...are.com,
linux-ia64@...r.kernel.org, linux-arch@...r.kernel.org,
loongarch@...ts.linux.dev, kvm@...r.kernel.org,
linux-s390@...r.kernel.org, linux-sgx@...r.kernel.org,
linux-um@...ts.infradead.org, linux-acpi@...r.kernel.org,
linux-crypto@...r.kernel.org, nvdimm@...ts.linux.dev,
dmaengine@...r.kernel.org, amd-gfx@...ts.freedesktop.org,
dri-devel@...ts.freedesktop.org, etnaviv@...ts.freedesktop.org,
linux-samsung-soc@...r.kernel.org, intel-gfx@...ts.freedesktop.org,
linux-mediatek@...ts.infradead.org, linux-arm-msm@...r.kernel.org,
freedreno@...ts.freedesktop.org,
linux-rockchip@...ts.infradead.org, linux-tegra@...r.kernel.org,
virtualization@...ts.linux-foundation.org,
xen-devel@...ts.xenproject.org,
linux-stm32@...md-mailman.stormreply.com,
linux-rdma@...r.kernel.org, linux-media@...r.kernel.org,
linux-accelerators@...ts.ozlabs.org, sparclinux@...r.kernel.org,
linux-scsi@...r.kernel.org, linux-staging@...ts.linux.dev,
target-devel@...r.kernel.org, linux-usb@...r.kernel.org,
netdev@...r.kernel.org, linux-fbdev@...r.kernel.org,
linux-aio@...ck.org, linux-fsdevel@...r.kernel.org,
linux-erofs@...ts.ozlabs.org, linux-ext4@...r.kernel.org,
devel@...ts.orangefs.org, kexec@...ts.infradead.org,
linux-xfs@...r.kernel.org, bpf@...r.kernel.org,
linux-perf-users@...r.kernel.org, kasan-dev@...glegroups.com,
selinux@...r.kernel.org, alsa-devel@...a-project.org,
kernel-team@...roid.com
Subject: Re: [PATCH v2 4/6] mm: replace vma->vm_flags indirect modification
in ksm_madvise
On Wed, Jan 25, 2023 at 12:38:49AM -0800, Suren Baghdasaryan wrote:
> 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. Add a BUG_ON check in ksm_madvise() to catch indirect
> vm_flags modification attempts.
>
> Signed-off-by: Suren Baghdasaryan <surenb@...gle.com>
Acked-by: Mike Rapoport (IBM) <rppt@...nel.org>
> ---
> arch/powerpc/kvm/book3s_hv_uvmem.c | 5 ++++-
> arch/s390/mm/gmap.c | 5 ++++-
> mm/khugepaged.c | 2 ++
> mm/ksm.c | 2 ++
> 4 files changed, 12 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;
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 8abc59345bf2..76b24cd0c179 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -354,6 +354,8 @@ struct attribute_group khugepaged_attr_group = {
> int hugepage_madvise(struct vm_area_struct *vma,
> unsigned long *vm_flags, int advice)
> {
> + /* vma->vm_flags can be changed only using modifier functions */
> + BUG_ON(vm_flags == &vma->vm_flags);
> switch (advice) {
> case MADV_HUGEPAGE:
> #ifdef CONFIG_S390
> diff --git a/mm/ksm.c b/mm/ksm.c
> index 04f1c8c2df11..992b2be9f5e6 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -2573,6 +2573,8 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
> struct mm_struct *mm = vma->vm_mm;
> int err;
>
> + /* vma->vm_flags can be changed only using modifier functions */
> + BUG_ON(vm_flags == &vma->vm_flags);
> switch (advice) {
> case MADV_MERGEABLE:
> /*
> --
> 2.39.1
>
>
Powered by blists - more mailing lists